Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TryCatch.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Events;
6
8{
12 public class TryCatch : BinaryOperator
13 {
22 public TryCatch(ScriptNode Statement, ScriptNode CatchStatement, int Start, int Length, Expression Expression)
23 : base(Statement, CatchStatement, Start, Length, Expression)
24 {
25 }
26
33 {
34 try
35 {
36 return this.left.Evaluate(Variables);
37 }
38 catch (Exception ex)
39 {
40 object Bak = Variables["Exception"];
41 Variables["Exception"] = Log.UnnestException(ex);
42 try
43 {
44 return this.right.Evaluate(Variables);
45 }
46 finally
47 {
48 if (Bak is null)
49 Variables.Remove("Exception");
50 else
51 Variables["Exception"] = Bak;
52 }
53 }
54 }
55
61 public override async Task<IElement> EvaluateAsync(Variables Variables)
62 {
63 if (!this.isAsync)
64 return this.Evaluate(Variables);
65
66 try
67 {
68 return await this.left.EvaluateAsync(Variables);
69 }
70 catch (Exception ex)
71 {
72 object Bak = Variables["Exception"];
73 Variables["Exception"] = Log.UnnestException(ex);
74 try
75 {
76 return await this.right.EvaluateAsync(Variables);
77 }
78 finally
79 {
80 if (Bak is null)
81 Variables.Remove("Exception");
82 else
83 Variables["Exception"] = Bak;
84 }
85 }
86 }
87 }
88}
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
Base class for all binary operators.
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
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: TryCatch.cs:32
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: TryCatch.cs:61
TryCatch(ScriptNode Statement, ScriptNode CatchStatement, int Start, int Length, Expression Expression)
Try-Catch operator.
Definition: TryCatch.cs:22
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