mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
Move cpp exception handler from system to excpt next to the signal handler (#9435)
This commit is contained in:
@@ -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".}
|
||||
|
||||
@@ -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.} =
|
||||
|
||||
Reference in New Issue
Block a user