diff options
author | yglukhov <yuriy.glukhov@gmail.com> | 2015-06-15 23:08:38 +0300 |
---|---|---|
committer | yglukhov <yuriy.glukhov@gmail.com> | 2015-06-15 23:08:38 +0300 |
commit | fa1f3aecce3398f4d7afe69294ba9b3f928a66a2 (patch) | |
tree | c65c481947566c282fbbfb236e412f0db6aacdc7 /lib/system | |
parent | 090fc336416b9f7f9ee54dd8991bf1760d81df50 (diff) | |
download | Nim-fa1f3aecce3398f4d7afe69294ba9b3f928a66a2.tar.gz |
Unhandled exceptions handling brought back.
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/jssys.nim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index a6711a778..4d5ba1f73 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -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.} = |