mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Merge pull request #4670 from yglukhov/js-getcurex
Fixed getCurrentException and getCurrentExceptionMsg. Closes #4635
This commit is contained in:
@@ -47,11 +47,30 @@ proc nimCharToStr(x: char): string {.compilerproc.} =
|
||||
result = newString(1)
|
||||
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 =
|
||||
if lastJSError != nil:
|
||||
return $lastJSError.message
|
||||
else:
|
||||
return ""
|
||||
if isNimException():
|
||||
return cast[Exception](lastJSError).msg
|
||||
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 =
|
||||
type
|
||||
@@ -130,12 +149,7 @@ proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
||||
raise newException(ReraiseError, "no exception to reraise")
|
||||
else:
|
||||
if excHandler == 0:
|
||||
var isNimException: bool
|
||||
when defined(nimphp):
|
||||
asm "`isNimException` = isset(`lastJSError`['m_type']);"
|
||||
else:
|
||||
asm "`isNimException` = lastJSError.m_type;"
|
||||
if isNimException:
|
||||
if isNimException():
|
||||
unhandledException(cast[ref Exception](lastJSError))
|
||||
|
||||
asm "throw lastJSError;"
|
||||
|
||||
@@ -9,7 +9,7 @@ FINALLY
|
||||
RECOVER
|
||||
|
||||
BEFORE
|
||||
EXCEPT
|
||||
EXCEPT: IOError: hi
|
||||
FINALLY
|
||||
'''
|
||||
"""
|
||||
@@ -52,10 +52,10 @@ echo ""
|
||||
proc return_in_except =
|
||||
try:
|
||||
echo "BEFORE"
|
||||
raise newException(IOError, "")
|
||||
raise newException(IOError, "hi")
|
||||
|
||||
except:
|
||||
echo "EXCEPT"
|
||||
echo "EXCEPT: ", getCurrentException().name, ": ", getCurrentExceptionMsg()
|
||||
return
|
||||
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user