mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-03 04:24:45 +00:00
@@ -468,19 +468,36 @@ when defined(endb):
|
||||
when defined(cpp) and appType != "lib" and
|
||||
not defined(js) and not defined(nimscript) and
|
||||
hostOS != "standalone" and not defined(noCppExceptions):
|
||||
|
||||
type
|
||||
StdException {.importcpp: "std::exception", header: "<exception>".} = object
|
||||
|
||||
proc what(ex: StdException): cstring {.importcpp: "((char *)#.what())".}
|
||||
|
||||
proc setTerminate(handler: proc() {.noconv.})
|
||||
{.importc: "std::set_terminate", header: "<exception>".}
|
||||
|
||||
setTerminate proc() {.noconv.} =
|
||||
# Remove ourself as a handler, reinstalling the default handler.
|
||||
setTerminate(nil)
|
||||
|
||||
var msg = "Unknown error in unexpected exception handler"
|
||||
try:
|
||||
raise
|
||||
except Exception:
|
||||
msg = currException.getStackTrace() & "Error: unhandled exception: " &
|
||||
currException.msg & " [" & $currException.name & "]"
|
||||
except StdException as e:
|
||||
msg = "Error: unhandled cpp exception: " & $e.what()
|
||||
except:
|
||||
msg = "Error: unhandled unknown cpp exception"
|
||||
|
||||
when defined(genode):
|
||||
# stderr not available by default, use the LOG session
|
||||
echo currException.getStackTrace() & "Error: unhandled exception: " &
|
||||
currException.msg & " [" & $currException.name & "]\n"
|
||||
echo msg
|
||||
else:
|
||||
writeToStdErr currException.getStackTrace() & "Error: unhandled exception: " &
|
||||
currException.msg & " [" & $currException.name & "]\n"
|
||||
writeToStdErr msg & "\n"
|
||||
|
||||
quit 1
|
||||
|
||||
when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||
|
||||
Reference in New Issue
Block a user