mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-30 03:03:57 +00:00
Unhandled exceptions handling brought back.
This commit is contained in:
@@ -37,6 +37,7 @@ type
|
||||
|
||||
var
|
||||
framePtr {.importc, nodecl, volatile.}: PCallFrame
|
||||
excHandler {.importc, nodecl, volatile.}: int = 0
|
||||
lastJSError {.importc, nodecl, volatile.}: PJSError = nil
|
||||
|
||||
{.push stacktrace: off, profiler:off.}
|
||||
@@ -94,15 +95,38 @@ proc rawWriteStackTrace(): string =
|
||||
else:
|
||||
result = "No stack traceback available\n"
|
||||
|
||||
proc unhandledException(e: ref Exception) {.
|
||||
compilerproc, asmNoStackFrame.} =
|
||||
when NimStackTrace:
|
||||
var buf = rawWriteStackTrace()
|
||||
else:
|
||||
var buf = ""
|
||||
if e.msg != nil and e.msg[0] != '\0':
|
||||
add(buf, "Error: unhandled exception: ")
|
||||
add(buf, e.msg)
|
||||
else:
|
||||
add(buf, "Error: unhandled exception")
|
||||
add(buf, " [")
|
||||
add(buf, e.name)
|
||||
add(buf, "]\n")
|
||||
alert(buf)
|
||||
|
||||
proc raiseException(e: ref Exception, ename: cstring) {.
|
||||
compilerproc, asmNoStackFrame.} =
|
||||
e.name = ename
|
||||
if excHandler == 0:
|
||||
unhandledException(e)
|
||||
asm "throw `e`;"
|
||||
|
||||
proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
||||
if lastJSError == nil:
|
||||
raise newException(ReraiseError, "no exception to reraise")
|
||||
else:
|
||||
if excHandler == 0:
|
||||
var isNimException : bool
|
||||
asm "`isNimException` = lastJSError.m_type;"
|
||||
if isNimException:
|
||||
unhandledException(cast[ref Exception](lastJSError))
|
||||
asm "throw lastJSError;"
|
||||
|
||||
proc raiseOverflow {.exportc: "raiseOverflow", noreturn.} =
|
||||
|
||||
Reference in New Issue
Block a user