Open qb-0 opened 3 years ago
bad example because in devel this now gives static, not RT error (regardless of gc): Error: nil dereference is not allowed
however there is indeed a bug
when true:
import segfaults
var a: ptr int
try:
echo a[]
except NilAccessDefect:
echo "SegFault!"
default gc: prints SegFault!
gc:arc: hangs
And yes, segfaults is useful and needs to be supported, it's useful in cases where untrusted code should not cause a program to abort if it can (eg: repls, dll plugins)
And yes, segfaults is useful and needs to be supported, it's useful in cases where untrusted code should not cause a program to abort if it can (eg: repls, dll plugins)
Feel free to submit a patch then.
And yes, segfaults is useful and needs to be supported, it's useful in cases where untrusted code should not cause a program to abort if it can (eg: repls, dll plugins)
Or for applications shipped to users, where you want to capture errors in a crash log with full stack traces, that the user can the submit in a bug report.
note that you'll get a stacktrace without segfaults if you compile with --stacktrace
note that you'll get a stacktrace without segfaults if you compile with
--stacktrace
Yeah I know, but it just gets dumped to stderr, or in case of a Windows app, it gets shown in a popup dialog box. What I want is to write the stacktrace into a log file, so I need a mechanism to hook into this thing and change the behaviour of just dumping the stacktrace to stderr/displaying it in an alert box.
can you try unhandledExceptionHook and onUnhandledException?
(we should still fix the bug though)
It is related to goto
exception and the example works with exceptions:setjmp
.
change segfaults.nim
var SEGV_ACCERR {.importc, header: "<signal.h>".}: cint
...
if y.si_code == SEGV_MAPERR or y.si_code == SEGV_ACCERR:
compile with -d:noSignalHandler -d:nimPanics
you get Error: unhandled exception: Could not access value because it is nil. [NilAccessDefect]
lib/system/excpt.nim
also set a signal handler, so noSignalHandler
flag is required.
Edit: turns out only -d:nimPanics
required, it become unhandled exception.
SIGSEGV is not catchable with arc and
import segfaults
.Example
Current Output
Expected Output