0 votes
by Roger Levy (370 points)

No matter what I do, I can't define a stable custom exception handler.  I've put up with the GUI-based one which I have always disliked because it is fiddly, unstable, and can't be copy-pasted easily, but I've had enough and just want a standard terminal output.

As a simple test I want to just capture the error code.  At first I wanted to output to console but I've whittled it down to just that.

`0 @` works, but calling any external function leads to the handler being called in an infinite loop.

I've tried to get this to work on my 32-bit copy and the latest 64-bit release.

protectedexterns
variable err
 
: my-debugger  ( errcode *context -- filter )
    drop                      \ ignore context pointer for now
    \ task0-io op-handle !
 
    err !
    \ ." Exception code: "
    \ ." (terminal handler — no GUI popup)" cr
    false
;
 
' my-debugger to-callback DEBUGGER

: test 255 0 ['] getcurrentdirectory catch  err ? ;

3 Answers

0 votes
by Roger Levy (370 points)
edited by Roger Levy

An update:  I tried it with a function from a different library that's STDCALL and it catches exceptions without an endless loop there.  So it seems that the issue is with WINAPI somehow.

Another update:  Claude AI explained it to me and got me a working exception handler.  Didn't realize that it was this low-level!

0 votes
ago by Bart Nelson (820 points)
Our version for Linux64 attempts to give you as much info as possible e.g.

Arithmetic error (e.g. divide by zero), probably in DIVZERO, called from:
THROWTESTZ THROWTEST (INTERPRET) DEFER CATCH
0 votes
ago by Bart Nelson (820 points)
We recently extended ours to include tracing of exceptions in external library functions e.g.

Illegal memory access, probably in external library: /lib/x86_64-linux-gnu/libc.so.6, called from:
STRLEN THROWTESTL THROWTEST (INTERPRET) DEFER
...