1const NimStackTraceMsgs = 2 when defined(nimHasStacktraceMsgs): compileOption("stacktraceMsgs") 3 else: false 4 5type 6 RootEffect* {.compilerproc.} = object of RootObj ## \ 7 ## Base effect class. 8 ## 9 ## Each effect should inherit from `RootEffect` unless you know what 10 ## you're doing. 11 TimeEffect* = object of RootEffect ## Time effect. 12 IOEffect* = object of RootEffect ## IO effect. 13 ReadIOEffect* = object of IOEffect ## Effect describing a read IO operation. 14 WriteIOEffect* = object of IOEffect ## Effect describing a write IO operation. 15 ExecIOEffect* = object of IOEffect ## Effect describing an executing IO operation. 16 17 StackTraceEntry* = object ## In debug mode exceptions store the stack trace that led 18 ## to them. A `StackTraceEntry` is a single entry of the 19 ## stack trace. 20 procname*: cstring ## Name of the proc that is currently executing. 21 line*: int ## Line number of the proc that is currently executing. 22 filename*: cstring ## Filename of the proc that is currently executing. 23 when NimStackTraceMsgs: 24 frameMsg*: string ## When a stacktrace is generated in a given frame and 25 ## rendered at a later time, we should ensure the stacktrace 26 ## data isn't invalidated; any pointer into PFrame is 27 ## subject to being invalidated so shouldn't be stored. 28 when defined(nimStackTraceOverride): 29 programCounter*: uint ## Program counter - will be used to get the rest of the info, 30 ## when `$` is called on this type. We can't use 31 ## "cuintptr_t" in here. 32 procnameStr*, filenameStr*: string ## GC-ed alternatives to "procname" and "filename" 33 34 Exception* {.compilerproc, magic: "Exception".} = object of RootObj ## \ 35 ## Base exception class. 36 ## 37 ## Each exception has to inherit from `Exception`. See the full `exception 38 ## hierarchy <manual.html#exception-handling-exception-hierarchy>`_. 39 parent*: ref Exception ## Parent exception (can be used as a stack). 40 name*: cstring ## The exception's name is its Nim identifier. 41 ## This field is filled automatically in the 42 ## `raise` statement. 43 msg* {.exportc: "message".}: string ## The exception's message. Not 44 ## providing an exception message 45 ## is bad style. 46 when defined(js): 47 trace: string 48 else: 49 trace: seq[StackTraceEntry] 50 up: ref Exception # used for stacking exceptions. Not exported! 51 52 Defect* = object of Exception ## \ 53 ## Abstract base class for all exceptions that Nim's runtime raises 54 ## but that are strictly uncatchable as they can also be mapped to 55 ## a `quit` / `trap` / `exit` operation. 56 57 CatchableError* = object of Exception ## \ 58 ## Abstract class for all exceptions that are catchable. 59 IOError* = object of CatchableError ## \ 60 ## Raised if an IO error occurred. 61 EOFError* = object of IOError ## \ 62 ## Raised if an IO "end of file" error occurred. 63 OSError* = object of CatchableError ## \ 64 ## Raised if an operating system service failed. 65 errorCode*: int32 ## OS-defined error code describing this error. 66 LibraryError* = object of OSError ## \ 67 ## Raised if a dynamic library could not be loaded. 68 ResourceExhaustedError* = object of CatchableError ## \ 69 ## Raised if a resource request could not be fulfilled. 70 ArithmeticDefect* = object of Defect ## \ 71 ## Raised if any kind of arithmetic error occurred. 72 DivByZeroDefect* = object of ArithmeticDefect ## \ 73 ## Raised for runtime integer divide-by-zero errors. 74 75 OverflowDefect* = object of ArithmeticDefect ## \ 76 ## Raised for runtime integer overflows. 77 ## 78 ## This happens for calculations whose results are too large to fit in the 79 ## provided bits. 80 AccessViolationDefect* = object of Defect ## \ 81 ## Raised for invalid memory access errors 82 AssertionDefect* = object of Defect ## \ 83 ## Raised when assertion is proved wrong. 84 ## 85 ## Usually the result of using the `assert() template 86 ## <assertions.html#assert.t,untyped,string>`_. 87 ValueError* = object of CatchableError ## \ 88 ## Raised for string and object conversion errors. 89 KeyError* = object of ValueError ## \ 90 ## Raised if a key cannot be found in a table. 91 ## 92 ## Mostly used by the `tables <tables.html>`_ module, it can also be raised 93 ## by other collection modules like `sets <sets.html>`_ or `strtabs 94 ## <strtabs.html>`_. 95 OutOfMemDefect* = object of Defect ## \ 96 ## Raised for unsuccessful attempts to allocate memory. 97 IndexDefect* = object of Defect ## \ 98 ## Raised if an array index is out of bounds. 99 100 FieldDefect* = object of Defect ## \ 101 ## Raised if a record field is not accessible because its discriminant's 102 ## value does not fit. 103 RangeDefect* = object of Defect ## \ 104 ## Raised if a range check error occurred. 105 StackOverflowDefect* = object of Defect ## \ 106 ## Raised if the hardware stack used for subroutine calls overflowed. 107 ReraiseDefect* = object of Defect ## \ 108 ## Raised if there is no exception to reraise. 109 ObjectAssignmentDefect* = object of Defect ## \ 110 ## Raised if an object gets assigned to its parent's object. 111 ObjectConversionDefect* = object of Defect ## \ 112 ## Raised if an object is converted to an incompatible object type. 113 ## You can use `of` operator to check if conversion will succeed. 114 FloatingPointDefect* = object of Defect ## \ 115 ## Base class for floating point exceptions. 116 FloatInvalidOpDefect* = object of FloatingPointDefect ## \ 117 ## Raised by invalid operations according to IEEE. 118 ## 119 ## Raised by `0.0/0.0`, for example. 120 FloatDivByZeroDefect* = object of FloatingPointDefect ## \ 121 ## Raised by division by zero. 122 ## 123 ## Divisor is zero and dividend is a finite nonzero number. 124 FloatOverflowDefect* = object of FloatingPointDefect ## \ 125 ## Raised for overflows. 126 ## 127 ## The operation produced a result that exceeds the range of the exponent. 128 FloatUnderflowDefect* = object of FloatingPointDefect ## \ 129 ## Raised for underflows. 130 ## 131 ## The operation produced a result that is too small to be represented as a 132 ## normal number. 133 FloatInexactDefect* = object of FloatingPointDefect ## \ 134 ## Raised for inexact results. 135 ## 136 ## The operation produced a result that cannot be represented with infinite 137 ## precision -- for example: `2.0 / 3.0, log(1.1)` 138 ## 139 ## **Note**: Nim currently does not detect these! 140 DeadThreadDefect* = object of Defect ## \ 141 ## Raised if it is attempted to send a message to a dead thread. 142 NilAccessDefect* = object of Defect ## \ 143 ## Raised on dereferences of `nil` pointers. 144 ## 145 ## This is only raised if the `segfaults module <segfaults.html>`_ was imported! 146 147 ArithmeticError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect 148 DivByZeroError* {.deprecated: "See corresponding Defect".} = DivByZeroDefect 149 OverflowError* {.deprecated: "See corresponding Defect".} = OverflowDefect 150 AccessViolationError* {.deprecated: "See corresponding Defect".} = AccessViolationDefect 151 AssertionError* {.deprecated: "See corresponding Defect".} = AssertionDefect 152 OutOfMemError* {.deprecated: "See corresponding Defect".} = OutOfMemDefect 153 IndexError* {.deprecated: "See corresponding Defect".} = IndexDefect 154 155 FieldError* {.deprecated: "See corresponding Defect".} = FieldDefect 156 RangeError* {.deprecated: "See corresponding Defect".} = RangeDefect 157 StackOverflowError* {.deprecated: "See corresponding Defect".} = StackOverflowDefect 158 ReraiseError* {.deprecated: "See corresponding Defect".} = ReraiseDefect 159 ObjectAssignmentError* {.deprecated: "See corresponding Defect".} = ObjectAssignmentDefect 160 ObjectConversionError* {.deprecated: "See corresponding Defect".} = ObjectConversionDefect 161 FloatingPointError* {.deprecated: "See corresponding Defect".} = FloatingPointDefect 162 FloatInvalidOpError* {.deprecated: "See corresponding Defect".} = FloatInvalidOpDefect 163 FloatDivByZeroError* {.deprecated: "See corresponding Defect".} = FloatDivByZeroDefect 164 FloatOverflowError* {.deprecated: "See corresponding Defect".} = FloatOverflowDefect 165 FloatUnderflowError* {.deprecated: "See corresponding Defect".} = FloatUnderflowDefect 166 FloatInexactError* {.deprecated: "See corresponding Defect".} = FloatInexactDefect 167 DeadThreadError* {.deprecated: "See corresponding Defect".} = DeadThreadDefect 168 NilAccessError* {.deprecated: "See corresponding Defect".} = NilAccessDefect 169