Unhandled exceptions handling brought back.

This commit is contained in:
yglukhov
2015-06-15 23:08:38 +03:00
parent 090fc33641
commit fa1f3aecce
2 changed files with 35 additions and 8 deletions

View File

@@ -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.} =