1
2
3
4
5
6 namespace System
7 {
8 public class Exception
9 {
10 public nothrow Exception(const string& message_) : message(message_), callStack(System.Runtime.GetCallStack())
11 {
12 System.Runtime.DisposeCallStack();
13 }
14 public virtual default ~Exception();
15 public inline nothrow const string& Message() const
16 {
17 return message;
18 }
19 public inline nothrow const string& CallStack() const
20 {
21 return callStack;
22 }
23 public virtual nothrow string ToString() const
24 {
25 string s = typename(*this);
26 s.Append(": ").Append(message).Append("\nCALL STACK:\n").Append(callStack);
27 return s;
28 }
29 private string message;
30 private string callStack;
31 }
32
33 public class ExceptionPtr
34 {
35 public nothrow ExceptionPtr() : exception(null), exceptionClassIdHi(0u), exceptionClassIdLo(0u)
36 {
37 }
38 public nothrow ExceptionPtr(void* exception_, ulong exceptionClassIdHi_, ulong exceptionClassIdLo_) :
39 exception(exception_), exceptionClassIdHi(exceptionClassIdHi_), exceptionClassIdLo(exceptionClassIdLo_)
40 {
41 }
42 public inline nothrow void* Exception() const
43 {
44 return exception;
45 }
46 public inline nothrow ulong ExceptionClassIdHi() const
47 {
48 return exceptionClassIdHi;
49 }
50 public inline nothrow ulong ExceptionClassIdLo() const
51 {
52 return exceptionClassIdLo;
53 }
54 private void* exception;
55 private ulong exceptionClassIdHi;
56 private ulong exceptionClassIdLo;
57 }
58
59 public nothrow ExceptionPtr CaptureCurrentException()
60 {
61 void* exception;
62 ulong exceptionClassIdHi;
63 ulong exceptionClassIdLo;
64 RtCaptureException(exception, exceptionClassIdHi, exceptionClassIdLo);
65 return ExceptionPtr(exception, exceptionClassIdHi, exceptionClassIdLo);
66 }
67
68 public void ThrowCapturedException(const ExceptionPtr& capturedException)
69 {
70 RtThrowCapturedException(capturedException.Exception(), capturedException.ExceptionClassIdHi(), capturedException.ExceptionClassIdLo());
71 }
72
73 public class NullPointerException : Exception
74 {
75 public nothrow NullPointerException() : base("null pointer exception")
76 {
77 }
78 }
79
80 public class IndexOutOfBoundsException : Exception
81 {
82 public nothrow IndexOutOfBoundsException() : base("index out of bounds")
83 {
84 }
85 }
86
87 public class InvalidParameterException : Exception
88 {
89 public nothrow InvalidParameterException() : base("invalid parameter")
90 {
91 }
92 }
93
94 public class PreconditionViolationException : Exception
95 {
96 public nothrow PreconditionViolationException() : base("precondition violation")
97 {
98 }
99 }
100
101 public void ThrowNullPointerException()
102 {
103 throw NullPointerException();
104 }
105
106 public void ThrowIndexOutOfBoundsException()
107 {
108 throw IndexOutOfBoundsException();
109 }
110
111 public void ThrowInvalidParameterException()
112 {
113 throw InvalidParameterException();
114 }
115
116 public void ThrowPreconditionViolationException()
117 {
118 throw PreconditionViolationException();
119 }
120 }