Move cpp exception handler from system to excpt next to the signal handler (#9435)

This commit is contained in:
cooldome
2019-02-08 21:42:45 +01:00
committed by Andreas Rumpf
parent 695206a00c
commit d70dd6f3cb
2 changed files with 18 additions and 20 deletions

View File

@@ -4184,26 +4184,6 @@ template doAssertRaises*(exception: typedesc, code: untyped): typed =
if wrong:
raiseAssert(astToStr(exception) & " wasn't raised by:\n" & astToStr(code))
when defined(cpp) and appType != "lib" and
not defined(js) and not defined(nimscript) and
hostOS != "standalone" and not defined(noCppExceptions):
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)
let ex = getCurrentException()
let trace = ex.getStackTrace()
when defined(genode):
# stderr not available by default, use the LOG session
echo trace & "Error: unhandled exception: " & ex.msg &
" [" & $ex.name & "]\n"
else:
cstderr.rawWrite trace & "Error: unhandled exception: " & ex.msg &
" [" & $ex.name & "]\n"
quit 1
when not defined(js):
proc toOpenArray*[T](x: seq[T]; first, last: int): openarray[T] {.
magic: "Slice".}

View File

@@ -471,6 +471,24 @@ when defined(endb):
var
dbgAborting: bool # whether the debugger wants to abort
when defined(cpp) and appType != "lib" and
not defined(js) and not defined(nimscript) and
hostOS != "standalone" and not defined(noCppExceptions):
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)
when defined(genode):
# stderr not available by default, use the LOG session
echo currException.getStackTrace() & "Error: unhandled exception: " &
currException.msg & " [" & $currException.name & "]\n"
else:
writeToStdErr currException.getStackTrace() & "Error: unhandled exception: " &
currException.msg & " [" & $currException.name & "]\n"
quit 1
when not defined(noSignalHandler) and not defined(useNimRtl):
proc signalHandler(sign: cint) {.exportc: "signalHandler", noconv.} =
template processSignal(s, action: untyped) {.dirty.} =