Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TryCatchFinally.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Events;
6
8{
13 {
23 public TryCatchFinally(ScriptNode Statement, ScriptNode CatchStatement, ScriptNode FinallyStatement, int Start, int Length, Expression Expression)
24 : base(Statement, CatchStatement, FinallyStatement, Start, Length, Expression)
25 {
26 }
27
34 {
35 try
36 {
37 return this.left.Evaluate(Variables);
38 }
39 catch (Exception ex)
40 {
41 object Bak = Variables["Exception"];
42 Variables["Exception"] = Log.UnnestException(ex);
43 try
44 {
45 return this.middle.Evaluate(Variables);
46 }
47 finally
48 {
49 if (Bak is null)
50 Variables.Remove("Exception");
51 else
52 Variables["Exception"] = Bak;
53 }
54 }
55 finally
56 {
57 this.right.Evaluate(Variables);
58 }
59 }
60
66 public override async Task<IElement> EvaluateAsync(Variables Variables)
67 {
68 if (!this.isAsync)
69 return this.Evaluate(Variables);
70
71 try
72 {
73 return await this.left.EvaluateAsync(Variables);
74 }
75 catch (Exception ex)
76 {
77 object Bak = Variables["Exception"];
78 Variables["Exception"] = Log.UnnestException(ex);
79 try
80 {
81 return await this.middle.EvaluateAsync(Variables);
82 }
83 finally
84 {
85 if (Bak is null)
86 Variables.Remove("Exception");
87 else
88 Variables["Exception"] = Bak;
89 }
90 }
91 finally
92 {
93 await this.right.EvaluateAsync(Variables);
94 }
95 }
96 }
97}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:818
Class managing a script expression.
Definition: Expression.cs:39
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Base class for all ternary operators.
ScriptNode middle
Middle operand.
TryCatchFinally(ScriptNode Statement, ScriptNode CatchStatement, ScriptNode FinallyStatement, int Start, int Length, Expression Expression)
Try-Catch-Finally operator.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Collection of variables.
Definition: Variables.cs:25
virtual bool Remove(string VariableName)
Removes a varaiable from the collection.
Definition: Variables.cs:147
Basic interface for all types of elements.
Definition: IElement.cs:20