[plt-scheme] Re: programmatically printing stack trace
At Tue, 23 Mar 2010 15:53:44 -0700, Kartik Agaram wrote:
> I've been struggling with the docs to answer this question: how can I
> print the current stack trace at a point in my program? I know I
> should use errortrace somehow, but beyond that I'm stumped. Any
> guidance much appreciated. Has anybody else tried to do anything
> similar with stack traces?
If you want the low-level stack trace, you can use
(print (continuation-mark-set->context (current-continuation-marks)))
I don't think errortrace gives you direct access to the context
information that it maintains --- which is better defined than the
low-level stack trace --- but you can raise and immediately catch an
exception:
(require errortrace)
(with-handlers ([exn? (lambda (exn)
(print-error-trace (current-output-port) exn))])
(error "catch me"))