Move cpp exception handler from system to excpt next to the signal handler (#9435)
This commit is contained in:
parent
695206a00c
commit
d70dd6f3cb
2 changed files with 18 additions and 20 deletions
|
|
@ -4184,26 +4184,6 @@ template doAssertRaises*(exception: typedesc, code: untyped): typed =
|
||||||
if wrong:
|
if wrong:
|
||||||
raiseAssert(astToStr(exception) & " wasn't raised by:\n" & astToStr(code))
|
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):
|
when not defined(js):
|
||||||
proc toOpenArray*[T](x: seq[T]; first, last: int): openarray[T] {.
|
proc toOpenArray*[T](x: seq[T]; first, last: int): openarray[T] {.
|
||||||
magic: "Slice".}
|
magic: "Slice".}
|
||||||
|
|
|
||||||
|
|
@ -471,6 +471,24 @@ when defined(endb):
|
||||||
var
|
var
|
||||||
dbgAborting: bool # whether the debugger wants to abort
|
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):
|
when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||||
proc signalHandler(sign: cint) {.exportc: "signalHandler", noconv.} =
|
proc signalHandler(sign: cint) {.exportc: "signalHandler", noconv.} =
|
||||||
template processSignal(s, action: untyped) {.dirty.} =
|
template processSignal(s, action: untyped) {.dirty.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue