--define:nimQuirky exception handling for Nim; in preparation of a blog post

This commit is contained in:
Andreas Rumpf 2019-01-03 18:56:05 +01:00
commit cb9110c43d
7 changed files with 77 additions and 32 deletions

View file

@ -2968,6 +2968,28 @@ when not declared(sysFatal):
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
rawoutput(message)
panic(arg)
elif defined(nimQuirky):
proc name(t: typedesc): string {.magic: "TypeTrait".}
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
var buf = newStringOfCap(200)
add(buf, "Error: unhandled exception: ")
add(buf, message)
add(buf, " [")
add(buf, name exceptn)
add(buf, "]")
echo buf
quit 1
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
var buf = newStringOfCap(200)
add(buf, "Error: unhandled exception: ")
add(buf, message)
add(buf, arg)
add(buf, " [")
add(buf, name exceptn)
add(buf, "]")
echo buf
quit 1
else:
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
var e: ref exceptn