Fixed and slightly changed exception handling.

This commit is contained in:
yglukhov 2015-06-13 18:49:29 +03:00
commit 090fc33641
2 changed files with 23 additions and 35 deletions

View file

@ -37,9 +37,6 @@ type
var
framePtr {.importc, nodecl, volatile.}: PCallFrame
excHandler {.importc, nodecl, volatile.}: PSafePoint = nil
# list of exception handlers
# a global variable for the root of all try blocks
lastJSError {.importc, nodecl, volatile.}: PJSError = nil
{.push stacktrace: off, profiler:off.}
@ -52,9 +49,7 @@ proc nimCharToStr(x: char): string {.compilerproc.} =
result[0] = x
proc getCurrentExceptionMsg*(): string =
if excHandler != nil and excHandler.exc != nil:
return $excHandler.exc.msg
elif lastJSError != nil:
if lastJSError != nil:
return $lastJSError.message
else:
return ""
@ -102,29 +97,13 @@ proc rawWriteStackTrace(): string =
proc raiseException(e: ref Exception, ename: cstring) {.
compilerproc, asmNoStackFrame.} =
e.name = ename
if excHandler != nil:
excHandler.exc = e
else:
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, ename)
add(buf, "]\n")
alert(buf)
asm """throw `e`;"""
asm "throw `e`;"
proc reraiseException() {.compilerproc, asmNoStackFrame.} =
if excHandler == nil:
if lastJSError == nil:
raise newException(ReraiseError, "no exception to reraise")
else:
asm """throw excHandler.exc;"""
asm "throw lastJSError;"
proc raiseOverflow {.exportc: "raiseOverflow", noreturn.} =
raise newException(OverflowError, "over- or underflow")