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:
Andreas Rumpf 2020-03-12 23:44:33 +01:00 • committed by GitHub
commit a6682de004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 441 additions and 142 deletions

View file

@ -24,7 +24,7 @@ when hostOS == "standalone":
rawoutput(message)
panic(arg)
elif (defined(nimQuirky) or gotoBasedExceptions) and not defined(nimscript):
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
import ansi_c
proc name(t: typedesc): string {.magic: "TypeTrait".}
@ -46,20 +46,9 @@ elif (defined(nimQuirky) or gotoBasedExceptions) and not defined(nimscript):
else:
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
when declared(owned):
var e: owned(ref exceptn)
else:
var e: ref exceptn
new(e)
e.msg = message
raise e
raise (ref exceptn)(msg: message)
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
when declared(owned):
var e: owned(ref exceptn)
else:
var e: ref exceptn
new(e)
e.msg = message & arg
raise e
raise (ref exceptn)(msg: message & arg)
{.pop.}