exceptions.nim 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ## Exception and effect types used in Nim code.
  2. type
  3. TimeEffect* = object of RootEffect ## Time effect.
  4. IOEffect* = object of RootEffect ## IO effect.
  5. ReadIOEffect* = object of IOEffect ## Effect describing a read IO operation.
  6. WriteIOEffect* = object of IOEffect ## Effect describing a write IO operation.
  7. ExecIOEffect* = object of IOEffect ## Effect describing an executing IO operation.
  8. type
  9. IOError* = object of CatchableError ## \
  10. ## Raised if an IO error occurred.
  11. EOFError* = object of IOError ## \
  12. ## Raised if an IO "end of file" error occurred.
  13. OSError* = object of CatchableError ## \
  14. ## Raised if an operating system service failed.
  15. errorCode*: int32 ## OS-defined error code describing this error.
  16. LibraryError* = object of OSError ## \
  17. ## Raised if a dynamic library could not be loaded.
  18. ResourceExhaustedError* = object of CatchableError ## \
  19. ## Raised if a resource request could not be fulfilled.
  20. ArithmeticDefect* = object of Defect ## \
  21. ## Raised if any kind of arithmetic error occurred.
  22. DivByZeroDefect* = object of ArithmeticDefect ## \
  23. ## Raised for runtime integer divide-by-zero errors.
  24. OverflowDefect* = object of ArithmeticDefect ## \
  25. ## Raised for runtime integer overflows.
  26. ##
  27. ## This happens for calculations whose results are too large to fit in the
  28. ## provided bits.
  29. AccessViolationDefect* = object of Defect ## \
  30. ## Raised for invalid memory access errors
  31. AssertionDefect* = object of Defect ## \
  32. ## Raised when assertion is proved wrong.
  33. ##
  34. ## Usually the result of using the `assert() template
  35. ## <assertions.html#assert.t,untyped,string>`_.
  36. ValueError* = object of CatchableError ## \
  37. ## Raised for string and object conversion errors.
  38. KeyError* = object of ValueError ## \
  39. ## Raised if a key cannot be found in a table.
  40. ##
  41. ## Mostly used by the `tables <tables.html>`_ module, it can also be raised
  42. ## by other collection modules like `sets <sets.html>`_ or `strtabs
  43. ## <strtabs.html>`_.
  44. OutOfMemDefect* = object of Defect ## \
  45. ## Raised for unsuccessful attempts to allocate memory.
  46. IndexDefect* = object of Defect ## \
  47. ## Raised if an array index is out of bounds.
  48. FieldDefect* = object of Defect ## \
  49. ## Raised if a record field is not accessible because its discriminant's
  50. ## value does not fit.
  51. RangeDefect* = object of Defect ## \
  52. ## Raised if a range check error occurred.
  53. StackOverflowDefect* = object of Defect ## \
  54. ## Raised if the hardware stack used for subroutine calls overflowed.
  55. ReraiseDefect* = object of Defect ## \
  56. ## Raised if there is no exception to reraise.
  57. ObjectAssignmentDefect* = object of Defect ## \
  58. ## Raised if an object gets assigned to its parent's object.
  59. ObjectConversionDefect* = object of Defect ## \
  60. ## Raised if an object is converted to an incompatible object type.
  61. ## You can use `of` operator to check if conversion will succeed.
  62. FloatingPointDefect* = object of Defect ## \
  63. ## Base class for floating point exceptions.
  64. FloatInvalidOpDefect* = object of FloatingPointDefect ## \
  65. ## Raised by invalid operations according to IEEE.
  66. ##
  67. ## Raised by `0.0/0.0`, for example.
  68. FloatDivByZeroDefect* = object of FloatingPointDefect ## \
  69. ## Raised by division by zero.
  70. ##
  71. ## Divisor is zero and dividend is a finite nonzero number.
  72. FloatOverflowDefect* = object of FloatingPointDefect ## \
  73. ## Raised for overflows.
  74. ##
  75. ## The operation produced a result that exceeds the range of the exponent.
  76. FloatUnderflowDefect* = object of FloatingPointDefect ## \
  77. ## Raised for underflows.
  78. ##
  79. ## The operation produced a result that is too small to be represented as a
  80. ## normal number.
  81. FloatInexactDefect* = object of FloatingPointDefect ## \
  82. ## Raised for inexact results.
  83. ##
  84. ## The operation produced a result that cannot be represented with infinite
  85. ## precision -- for example: `2.0 / 3.0, log(1.1)`
  86. ##
  87. ## **Note**: Nim currently does not detect these!
  88. DeadThreadDefect* = object of Defect ## \
  89. ## Raised if it is attempted to send a message to a dead thread.
  90. NilAccessDefect* = object of Defect ## \
  91. ## Raised on dereferences of `nil` pointers.
  92. ##
  93. ## This is only raised if the `segfaults module <segfaults.html>`_ was imported!
  94. when not defined(nimPreviewSlimSystem):
  95. type
  96. ArithmeticError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect
  97. DivByZeroError* {.deprecated: "See corresponding Defect".} = DivByZeroDefect
  98. OverflowError* {.deprecated: "See corresponding Defect".} = OverflowDefect
  99. AccessViolationError* {.deprecated: "See corresponding Defect".} = AccessViolationDefect
  100. AssertionError* {.deprecated: "See corresponding Defect".} = AssertionDefect
  101. OutOfMemError* {.deprecated: "See corresponding Defect".} = OutOfMemDefect
  102. IndexError* {.deprecated: "See corresponding Defect".} = IndexDefect
  103. FieldError* {.deprecated: "See corresponding Defect".} = FieldDefect
  104. RangeError* {.deprecated: "See corresponding Defect".} = RangeDefect
  105. StackOverflowError* {.deprecated: "See corresponding Defect".} = StackOverflowDefect
  106. ReraiseError* {.deprecated: "See corresponding Defect".} = ReraiseDefect
  107. ObjectAssignmentError* {.deprecated: "See corresponding Defect".} = ObjectAssignmentDefect
  108. ObjectConversionError* {.deprecated: "See corresponding Defect".} = ObjectConversionDefect
  109. FloatingPointError* {.deprecated: "See corresponding Defect".} = FloatingPointDefect
  110. FloatInvalidOpError* {.deprecated: "See corresponding Defect".} = FloatInvalidOpDefect
  111. FloatDivByZeroError* {.deprecated: "See corresponding Defect".} = FloatDivByZeroDefect
  112. FloatOverflowError* {.deprecated: "See corresponding Defect".} = FloatOverflowDefect
  113. FloatUnderflowError* {.deprecated: "See corresponding Defect".} = FloatUnderflowDefect
  114. FloatInexactError* {.deprecated: "See corresponding Defect".} = FloatInexactDefect
  115. DeadThreadError* {.deprecated: "See corresponding Defect".} = DeadThreadDefect
  116. NilAccessError* {.deprecated: "See corresponding Defect".} = NilAccessDefect