mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
* 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
55 lines
1.4 KiB
Nim
55 lines
1.4 KiB
Nim
#
|
|
#
|
|
# Nim's Runtime Library
|
|
# (c) Copyright 2019 Andreas Rumpf
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
|
|
{.push profiler: off.}
|
|
|
|
when defined(nimHasExceptionsQuery):
|
|
const gotoBasedExceptions = compileOption("exceptions", "goto")
|
|
else:
|
|
const gotoBasedExceptions = false
|
|
|
|
when hostOS == "standalone":
|
|
include "$projectpath/panicoverride"
|
|
|
|
proc sysFatal(exceptn: typedesc, message: string) {.inline.} =
|
|
panic(message)
|
|
|
|
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
|
|
rawoutput(message)
|
|
panic(arg)
|
|
|
|
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
|
import ansi_c
|
|
|
|
proc name(t: typedesc): string {.magic: "TypeTrait".}
|
|
|
|
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
|
|
writeStackTrace()
|
|
var buf = newStringOfCap(200)
|
|
add(buf, "Error: unhandled exception: ")
|
|
add(buf, message)
|
|
add(buf, arg)
|
|
add(buf, " [")
|
|
add(buf, name exceptn)
|
|
add(buf, "]\n")
|
|
cstderr.rawWrite buf
|
|
quit 1
|
|
|
|
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
|
sysFatal(exceptn, message, "")
|
|
|
|
else:
|
|
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
|
raise (ref exceptn)(msg: message)
|
|
|
|
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
|
|
raise (ref exceptn)(msg: message & arg)
|
|
|
|
{.pop.}
|