summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2019-04-11 12:51:51 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-04-11 13:51:51 +0200
commitde02fd0b898e41fa91087300d82573d83e357b34 (patch)
treeaf80eb8cf077bb93945553a10945b22c052b52d5 /lib/system
parenta2ad0697694139eaed78fe83dce99ded348dee3d (diff)
downloadNim-de02fd0b898e41fa91087300d82573d83e357b34.tar.gz
fixes #10765 (#10993) [backport]
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/excpt.nim25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index ec9d36c55..b421d9650 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -468,19 +468,36 @@ when defined(endb):
 when defined(cpp) and appType != "lib" and
     not defined(js) and not defined(nimscript) and
     hostOS != "standalone" and not defined(noCppExceptions):
+      
+  type 
+    StdException {.importcpp: "std::exception", header: "<exception>".} = object
+      
+  proc what(ex: StdException): cstring {.importcpp: "((char *)#.what())".}
+
   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)
 
+    var msg = "Unknown error in unexpected exception handler"
+    try:
+      raise
+    except Exception:
+      msg = currException.getStackTrace() & "Error: unhandled exception: " &
+        currException.msg & " [" & $currException.name & "]"
+    except StdException as e:
+      msg = "Error: unhandled cpp exception: " & $e.what()
+    except:
+      msg = "Error: unhandled unknown cpp exception"
+      
     when defined(genode):
       # stderr not available by default, use the LOG session
-      echo currException.getStackTrace() & "Error: unhandled exception: " &
-              currException.msg & " [" & $currException.name & "]\n"
+      echo msg
     else:
-      writeToStdErr currException.getStackTrace() & "Error: unhandled exception: " &
-              currException.msg & " [" & $currException.name & "]\n"
+      writeToStdErr msg & "\n"
+
     quit 1
 
 when not defined(noSignalHandler) and not defined(useNimRtl):