Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TryCatchFinallyHandler.cs
Go to the documentation of this file.
3
5
6internal sealed class TryCatchFinallyHandler
7{
8 internal readonly int TryStartIndex;
9
10 internal readonly int TryEndIndex;
11
12 internal readonly int FinallyStartIndex;
13
14 internal readonly int FinallyEndIndex;
15
16 internal readonly int GotoEndTargetIndex;
17
18 private readonly ExceptionHandler[] _handlers;
19
20 internal bool IsFinallyBlockExist => FinallyStartIndex != int.MaxValue;
21
23
24 internal bool IsCatchBlockExist => _handlers != null;
25
26 internal TryCatchFinallyHandler(int tryStart, int tryEnd, int gotoEndTargetIndex, ExceptionHandler[] handlers)
27 : this(tryStart, tryEnd, gotoEndTargetIndex, int.MaxValue, int.MaxValue, handlers)
28 {
29 }
30
31 internal TryCatchFinallyHandler(int tryStart, int tryEnd, int gotoEndLabelIndex, int finallyStart, int finallyEnd, ExceptionHandler[] handlers)
32 {
33 TryStartIndex = tryStart;
34 TryEndIndex = tryEnd;
35 FinallyStartIndex = finallyStart;
36 FinallyEndIndex = finallyEnd;
37 GotoEndTargetIndex = gotoEndLabelIndex;
38 _handlers = handlers;
39 }
40
41 internal bool HasHandler(InterpretedFrame frame, Exception exception, [NotNullWhen(true)] out ExceptionHandler handler, out object unwrappedException)
42 {
45 {
47 unwrappedException = ((ex != null) ? ex.WrappedException : exception);
48 Type type = unwrappedException.GetType();
49 ExceptionHandler[] handlers = _handlers;
50 foreach (ExceptionHandler exceptionHandler in handlers)
51 {
52 if (exceptionHandler.Matches(type) && (exceptionHandler.Filter == null || FilterPasses(frame, ref unwrappedException, exceptionHandler.Filter)))
53 {
54 handler = exceptionHandler;
55 return true;
56 }
57 }
58 }
59 else
60 {
61 unwrappedException = null;
62 }
63 handler = null;
64 return false;
65 }
66
67 private static bool FilterPasses(InterpretedFrame frame, ref object exception, ExceptionFilter filter)
68 {
69 Interpreter interpreter = frame.Interpreter;
70 Instruction[] instructions = interpreter.Instructions.Instructions;
71 int stackIndex = frame.StackIndex;
72 int instructionIndex = frame.InstructionIndex;
73 try
74 {
75 int num = (frame.InstructionIndex = interpreter._labels[filter.LabelIndex].Index);
76 frame.Push(exception);
77 while (num >= filter.StartIndex && num < filter.EndIndex)
78 {
79 num = (frame.InstructionIndex = num + instructions[num].Run(frame));
80 }
81 object obj = frame.Pop();
82 if ((bool)frame.Pop())
83 {
84 exception = obj;
85 return true;
86 }
87 }
88 catch
89 {
90 }
91 frame.StackIndex = stackIndex;
92 frame.InstructionIndex = instructionIndex;
93 return false;
94 }
95}
TryCatchFinallyHandler(int tryStart, int tryEnd, int gotoEndLabelIndex, int finallyStart, int finallyEnd, ExceptionHandler[] handlers)
TryCatchFinallyHandler(int tryStart, int tryEnd, int gotoEndTargetIndex, ExceptionHandler[] handlers)
static bool FilterPasses(InterpretedFrame frame, ref object exception, ExceptionFilter filter)
bool HasHandler(InterpretedFrame frame, Exception exception, [NotNullWhen(true)] out ExceptionHandler handler, out object unwrappedException)
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408