catchable defects (#13626)
* allow defects to be caught even for --exceptions:goto (WIP) * implemented the new --panics:on|off switch; refs https://github.com/nim-lang/RFCs/issues/180 * new implementation for integer overflow checking * produce a warning if a user-defined exception type inherits from Exception directly * applied Timothee's suggestions; improved the documentation and replace the term 'checked runtime check' by 'panic' * fixes #13627 * don't inherit from Exception directly
This commit is contained in:
parent
14b2354b7d
commit
a6682de004
35 changed files with 441 additions and 142 deletions
|
|
@ -28,6 +28,19 @@ proc raiseIndexError() {.compilerproc, noinline.} =
|
|||
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
||||
sysFatal(FieldError, f)
|
||||
|
||||
proc raiseRangeErrorI(i, a, b: BiggestInt) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorF(i, a, b: float) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
||||
# todo: better error reporting
|
||||
sysFatal(RangeError, "value out of range")
|
||||
|
||||
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
|
||||
proc chckIndx(i, a, b: int): int =
|
||||
if i >= a and i <= b:
|
||||
return i
|
||||
|
|
@ -116,6 +129,5 @@ when not defined(nimV2):
|
|||
return true
|
||||
|
||||
when defined(nimV2):
|
||||
proc nimFieldDiscriminantCheckV2(oldDiscVal, newDiscVal: uint8) {.compilerproc.} =
|
||||
if oldDiscVal != newDiscVal:
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
proc raiseObjectCaseTransition() {.compilerproc.} =
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue