How to log sclang errors (including stack trace)

Hey ya’ll,

Is it at all possible to log the backtrace and error info printed to the post window in sclang? By log I mean that I am keeping a log file for a long-running SC program, and I would like to be able to write any Errors and Exceptions that occur to this log file, including the stack trace.

I know that it’s possible to overwrite the default exception handler of the sclang process like this:

thisThread.exceptionHandler = {|ex| "GOT EXCEPTION %".format(ex).warn };

And I suspect this is where I should put my file logging code. I just can’t seem to find any way of accessing the stack trace. The documentation for Exception does point to some intruiging methods like protectedBacktrace but this does not seem to give me the stack trace when I attempt to log it.

Any thoughts?

Unfortunately, even though SC has a streaming interface for output – Post << something – and this would allow redirects easily, this is woefully underused. Exception:postProtectedBacktrace even uses CollStream to build the output string, but then hardcodes postln at the end! It could (but doesn’t) accept an argument stream(Post) and then do stream << (the output string) at the end. Then it would be easy to override the destination.

Next problem – un-protected backtraces are printed by a primitive. Language methods have no way to intercept.

I think SC needs some enhancements for this, unfortunately.

hjh

Oy… I see. This is very frustrating!

I’ve filed an issue here