summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-02-27 17:42:38 +0100
committerAraq <rumpf_a@web.de>2018-02-27 17:43:02 +0100
commitc9f184401cb0a7289119c1785c3af032f9998ff8 (patch)
tree62faddcd53a680cb3807035dfe6fcea494e30688 /lib
parent9c7374abcd2c1c79daccfef58c74964155985bbc (diff)
downloadNim-c9f184401cb0a7289119c1785c3af032f9998ff8.tar.gz
merged #6512 manually; fixes #6431
Diffstat (limited to 'lib')
-rw-r--r--lib/system.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 2b2ce7008..2f95b45f0 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -4117,3 +4117,17 @@ template doAssertRaises*(exception, code: untyped): typed =
     raiseAssert(astToStr(exception) &
                 " wasn't raised, another error was raised instead by:\n"&
                 astToStr(code))
+
+when defined(cpp) and appType != "lib" and not defined(js) and
+    not defined(nimscript) and hostOS != "standalone":
+  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()
+    stderr.write trace & "Error: unhandled exception: " & ex.msg &
+                 " [" & $ex.name & "]\n"
+    quit 1