Fixed getCurrentException and getCurrentExceptionMsg. Closes #4635
This commit is contained in:
parent
12cd8fe9e2
commit
f12f27c185
2 changed files with 26 additions and 12 deletions
|
|
@ -47,11 +47,30 @@ proc nimCharToStr(x: char): string {.compilerproc.} =
|
||||||
result = newString(1)
|
result = newString(1)
|
||||||
result[0] = x
|
result[0] = x
|
||||||
|
|
||||||
|
proc isNimException(): bool {.asmNoStackFrame.} =
|
||||||
|
when defined(nimphp):
|
||||||
|
asm "return isset(`lastJSError`['m_type']);"
|
||||||
|
else:
|
||||||
|
asm "return `lastJSError`.m_type;"
|
||||||
|
|
||||||
|
proc getCurrentException*(): ref Exception =
|
||||||
|
if isNimException(): result = cast[ref Exception](lastJSError)
|
||||||
|
|
||||||
proc getCurrentExceptionMsg*(): string =
|
proc getCurrentExceptionMsg*(): string =
|
||||||
if lastJSError != nil:
|
if lastJSError != nil:
|
||||||
return $lastJSError.message
|
if isNimException():
|
||||||
else:
|
return cast[Exception](lastJSError).msg
|
||||||
return ""
|
else:
|
||||||
|
when not defined(nimphp):
|
||||||
|
var msg: cstring
|
||||||
|
{.emit: """
|
||||||
|
if (`lastJSError`.message !== undefined) {
|
||||||
|
`msg` = `lastJSError`.message;
|
||||||
|
}
|
||||||
|
""".}
|
||||||
|
if not msg.isNil:
|
||||||
|
return $msg
|
||||||
|
return ""
|
||||||
|
|
||||||
proc auxWriteStackTrace(f: PCallFrame): string =
|
proc auxWriteStackTrace(f: PCallFrame): string =
|
||||||
type
|
type
|
||||||
|
|
@ -130,12 +149,7 @@ proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
||||||
raise newException(ReraiseError, "no exception to reraise")
|
raise newException(ReraiseError, "no exception to reraise")
|
||||||
else:
|
else:
|
||||||
if excHandler == 0:
|
if excHandler == 0:
|
||||||
var isNimException: bool
|
if isNimException():
|
||||||
when defined(nimphp):
|
|
||||||
asm "`isNimException` = isset(`lastJSError`['m_type']);"
|
|
||||||
else:
|
|
||||||
asm "`isNimException` = lastJSError.m_type;"
|
|
||||||
if isNimException:
|
|
||||||
unhandledException(cast[ref Exception](lastJSError))
|
unhandledException(cast[ref Exception](lastJSError))
|
||||||
|
|
||||||
asm "throw lastJSError;"
|
asm "throw lastJSError;"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ FINALLY
|
||||||
RECOVER
|
RECOVER
|
||||||
|
|
||||||
BEFORE
|
BEFORE
|
||||||
EXCEPT
|
EXCEPT: IOError: hi
|
||||||
FINALLY
|
FINALLY
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
@ -52,10 +52,10 @@ echo ""
|
||||||
proc return_in_except =
|
proc return_in_except =
|
||||||
try:
|
try:
|
||||||
echo "BEFORE"
|
echo "BEFORE"
|
||||||
raise newException(IOError, "")
|
raise newException(IOError, "hi")
|
||||||
|
|
||||||
except:
|
except:
|
||||||
echo "EXCEPT"
|
echo "EXCEPT: ", getCurrentException().name, ": ", getCurrentExceptionMsg()
|
||||||
return
|
return
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue