From c9f184401cb0a7289119c1785c3af032f9998ff8 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 27 Feb 2018 17:42:38 +0100 Subject: merged #6512 manually; fixes #6431 --- lib/system.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') 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: "".} + 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 -- cgit 1.4.1-2-gfad0