diff options
author | alaviss <alaviss@users.noreply.github.com> | 2018-11-22 20:46:07 +0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-11-22 14:46:07 +0100 |
commit | c7eba64dee9a8e686fde03ee2a2992e93a084927 (patch) | |
tree | 372894fe76c40d40022926069cf488eabbd0d0ea | |
parent | 02351d02e752173b3ef168e1e113d6bdbf4a593d (diff) | |
download | Nim-c7eba64dee9a8e686fde03ee2a2992e93a084927.tar.gz |
don't raise exception in the default handler (#9783)
fixes #9657
-rw-r--r-- | lib/system/dyncalls.nim | 7 | ||||
-rw-r--r-- | lib/system/excpt.nim | 9 | ||||
-rw-r--r-- | tests/exception/t9657.nim | 6 |
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/system/dyncalls.nim b/lib/system/dyncalls.nim index d6c361b2c..70bdc429b 100644 --- a/lib/system/dyncalls.nim +++ b/lib/system/dyncalls.nim @@ -17,13 +17,6 @@ const NilLibHandle: LibHandle = nil -proc c_fwrite(buf: pointer, size, n: csize, f: File): cint {. - importc: "fwrite", header: "<stdio.h>".} - -proc rawWrite(f: File, s: string|cstring) = - # we cannot throw an exception here! - discard c_fwrite(cstring(s), 1, s.len, f) - proc nimLoadLibraryError(path: string) = # carefully written to avoid memory allocation: stderr.rawWrite("could not load: ") diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 778137668..a6da8f5a3 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -17,8 +17,15 @@ var ## instead of stdmsg.write when printing stacktrace. ## Unstable API. +proc c_fwrite(buf: pointer, size, n: csize, f: File): cint {. + importc: "fwrite", header: "<stdio.h>".} + +proc rawWrite(f: File, s: string|cstring) = + # we cannot throw an exception here! + discard c_fwrite(cstring(s), 1, s.len, f) + when not defined(windows) or not defined(guiapp): - proc writeToStdErr(msg: cstring) = write(stdmsg, msg) + proc writeToStdErr(msg: cstring) = rawWrite(stdmsg, msg) else: proc MessageBoxA(hWnd: cint, lpText, lpCaption: cstring, uType: int): int32 {. diff --git a/tests/exception/t9657.nim b/tests/exception/t9657.nim new file mode 100644 index 000000000..5d5164f4f --- /dev/null +++ b/tests/exception/t9657.nim @@ -0,0 +1,6 @@ +discard """ + action: run + exitcode: 1 +""" +close stdmsg +writeLine stdmsg, "exception!" |