diff options
author | cooldome <cdome@bk.ru> | 2019-02-08 21:42:45 +0100 |
---|---|---|
committer | Miran <narimiran@disroot.org> | 2019-02-08 21:42:45 +0100 |
commit | 55fe7c114ed04cb18a8c33c0039ae66d6125c24f (patch) | |
tree | 7e6f3944cadb154fc747e87ae962d8678f29f84e | |
parent | e0e8fdf737ff8c70e8f80438f5bafd8a273dc159 (diff) | |
download | Nim-55fe7c114ed04cb18a8c33c0039ae66d6125c24f.tar.gz |
Move cpp exception handler from system to excpt next to the signal handler (#9435)
-rw-r--r-- | lib/system.nim | 20 | ||||
-rw-r--r-- | lib/system/excpt.nim | 18 |
2 files changed, 18 insertions, 20 deletions
diff --git a/lib/system.nim b/lib/system.nim index 7febde127..ca4ac33cb 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -4166,26 +4166,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".} diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 9d33db4cb..dbdd038a4 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -469,6 +469,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.} = |