[racket] Exception Stack Trace Troubles

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Jun 24 01:08:11 EDT 2012

A few minutes ago, Chad Albers wrote:
> Hi,
> 
> Is there some sort of 'secret' to acquiring the stack trace of an
> exception?  It is my understanding that when an exception is raised
> with the 'error' procedure in creates a exn:fail structure that has
> a message field and a continuation-marks field.  Presumably the
> stack trace is in the continuation-marks field.  To actually get the
> stack trace I need to call the following:
> 
> (continuation-mark-set->context (exn-continuation-marks exception))

This should work -- for example, I see a stack trace with:

  (with-handlers ([void (λ (e) (continuation-mark-set->context
                                (exn-continuation-marks e)))])
    (+ 1 "two"))


> However, whenever I call this, it yields an empty list: () - Not a
> stack trace.

That can happen from running code in threads which start from an empty
context.  For example, doing the above in a thread:

  (thread (λ () (printf "~s\n" ...same...)))

shows an empty trace.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.