Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EnterTryCatchFinallyInstruction.cs
Go to the documentation of this file.
2
4{
5 private readonly bool _hasFinally;
6
8
10
11 public override int ProducedContinuations
12 {
13 get
14 {
15 if (!_hasFinally)
16 {
17 return 0;
18 }
19 return 1;
20 }
21 }
22
23 public override string InstructionName
24 {
25 get
26 {
27 if (!_hasFinally)
28 {
29 return "EnterTryCatch";
30 }
31 return "EnterTryFinally";
32 }
33 }
34
35 internal void SetTryHandler(TryCatchFinallyHandler tryHandler)
36 {
37 _tryHandler = tryHandler;
38 }
39
40 private EnterTryCatchFinallyInstruction(int targetIndex, bool hasFinally)
41 : base(targetIndex)
42 {
43 _hasFinally = hasFinally;
44 }
45
46 internal static EnterTryCatchFinallyInstruction CreateTryFinally(int labelIndex)
47 {
48 return new EnterTryCatchFinallyInstruction(labelIndex, hasFinally: true);
49 }
50
52 {
53 return new EnterTryCatchFinallyInstruction(int.MaxValue, hasFinally: false);
54 }
55
56 public override int Run(InterpretedFrame frame)
57 {
58 if (_hasFinally)
59 {
61 }
62 int instructionIndex = frame.InstructionIndex;
63 frame.InstructionIndex++;
64 Instruction[] instructions = frame.Interpreter.Instructions.Instructions;
65 ExceptionHandler handler;
66 object unwrappedException;
67 try
68 {
69 int num = frame.InstructionIndex;
70 while (num >= _tryHandler.TryStartIndex && num < _tryHandler.TryEndIndex)
71 {
72 num = (frame.InstructionIndex = num + instructions[num].Run(frame));
73 }
75 {
76 frame.InstructionIndex += instructions[num].Run(frame);
77 }
78 }
79 catch (Exception exception) when (_tryHandler.HasHandler(frame, exception, out handler, out unwrappedException))
80 {
81 frame.InstructionIndex += frame.Goto(handler.LabelIndex, unwrappedException, gotoExceptionHandler: true);
82 bool flag = false;
83 try
84 {
85 int num2 = frame.InstructionIndex;
86 while (num2 >= handler.HandlerStartIndex && num2 < handler.HandlerEndIndex)
87 {
88 num2 = (frame.InstructionIndex = num2 + instructions[num2].Run(frame));
89 }
91 {
92 frame.InstructionIndex += instructions[num2].Run(frame);
93 }
94 }
95 catch (RethrowException)
96 {
97 flag = true;
98 }
99 if (flag)
100 {
101 throw;
102 }
103 }
104 finally
105 {
107 {
108 int num3 = (frame.InstructionIndex = _tryHandler.FinallyStartIndex);
110 {
111 num3 = (frame.InstructionIndex = num3 + instructions[num3].Run(frame));
112 }
113 }
114 }
115 return frame.InstructionIndex - instructionIndex;
116 }
117
118 public override string ToString()
119 {
120 if (!_hasFinally)
121 {
122 return "EnterTryCatch";
123 }
124 return "EnterTryFinally[" + _labelIndex + "]";
125 }
126}
static EnterTryCatchFinallyInstruction CreateTryFinally(int labelIndex)
int Goto(int labelIndex, object value, bool gotoExceptionHandler)
bool HasHandler(InterpretedFrame frame, Exception exception, [NotNullWhen(true)] out ExceptionHandler handler, out object unwrappedException)