forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TryCatchFinally.cs
69 lines (63 loc) · 1.77 KB
/
TryCatchFinally.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using BlocklyNet.Core.Model;
using BlocklyNet.Extensions.Builder;
namespace BlocklyNet.Extensions;
/// <summary>
/// Set a progress for the current script execution.
/// </summary>
[CustomBlock(
"try_catch_finally",
"",
@"{
""message0"": ""Try / Catch / Finally %1 Try %2 Catch %3 Finally %4"",
""args0"": [
{
""type"": ""input_dummy""
},
{
""type"": ""input_statement"",
""name"": ""TRY""
},
{
""type"": ""input_statement"",
""name"": ""CATCH""
},
{
""type"": ""input_statement"",
""name"": ""FINALLY""
}
],
""previousStatement"": null,
""nextStatement"": null,
""colour"": ""#107159"",
""tooltip"": ""Execute block with exception handling"",
""helpUrl"": """"
}",
""
)]
public class TryCatchFinally : Block
{
/// <inheritdoc/>
public override async Task<object?> EvaluateAsync(Context context)
{
try
{
/* Fetch the block to run. */
var exec = Statements.TryGet("TRY");
if (exec != null) await exec.EvaluateAsync(context);
}
catch (Exception)
{
/* Fetch the block to run. */
var report = Statements.TryGet("CATCH");
if (report != null) await report.EvaluateAsync(context);
}
finally
{
/* Fetch the block to run. */
var cleanup = Statements.TryGet("FINALLY");
if (cleanup != null) await cleanup.EvaluateAsync(context);
}
/* Proceed with next block in chain. */
return await base.EvaluateAsync(context);
}
}