Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ThrowInstruction.cs
Go to the documentation of this file.
2
4
5internal sealed class ThrowInstruction : Instruction
6{
7 internal static readonly ThrowInstruction Throw = new ThrowInstruction(hasResult: true, isRethrow: false);
8
9 internal static readonly ThrowInstruction VoidThrow = new ThrowInstruction(hasResult: false, isRethrow: false);
10
11 internal static readonly ThrowInstruction Rethrow = new ThrowInstruction(hasResult: true, isRethrow: true);
12
13 internal static readonly ThrowInstruction VoidRethrow = new ThrowInstruction(hasResult: false, isRethrow: true);
14
15 private readonly bool _hasResult;
16
17 private readonly bool _rethrow;
18
19 public override string InstructionName => "Throw";
20
21 public override int ProducedStack
22 {
23 get
24 {
25 if (!_hasResult)
26 {
27 return 0;
28 }
29 return 1;
30 }
31 }
32
33 public override int ConsumedStack => 1;
34
35 private ThrowInstruction(bool hasResult, bool isRethrow)
36 {
37 _hasResult = hasResult;
38 _rethrow = isRethrow;
39 }
40
41 public override int Run(InterpretedFrame frame)
42 {
43 Exception ex = WrapThrownObject(frame.Pop());
44 if (_rethrow)
45 {
46 throw new RethrowException();
47 }
48 throw ex;
49 }
50
51 private static Exception WrapThrownObject(object thrown)
52 {
53 object obj;
54 if (thrown != null)
55 {
56 obj = thrown as Exception;
57 if (obj == null)
58 {
59 return new RuntimeWrappedException(thrown);
60 }
61 }
62 else
63 {
64 obj = null;
65 }
66 return (Exception)obj;
67 }
68}