[prev in list] [next in list] [prev in thread] [next in thread] 

List:       racket-users
Subject:    [plt-scheme] Exception handling outside of Dr Scheme
From:       mflatt () cs ! utah ! edu (Matthew Flatt)
Date:       2008-01-30 14:37:42
Message-ID: 20080130143743.F2DA565008C () mail-svr1 ! cs ! utah ! edu
[Download RAW message or body]

At Wed, 30 Jan 2008 06:21:14 -0800, "Vincent Rayappa" wrote:
> Hello,
> 
> If I am using PLT Scheme outside of Dr. Scheme (via the Unix shebang
> notation), how do I get stack traces from a 'handled exception'?
> 
> For example:
> 
> (define (handle-error-p exn) #t)
> 
> (define (exception-handler exn)
>     (printf "Exception caught: ~a ~n" exn)
>     ;; --- How can I print the stack trace here inside the handler?
>     (do-clean-up))
> 
> (with-handlers
>   ((handle-error-p exception-handler))
>   (do-something ...)))
> 
> ---
> 
> How would I get the stack track inside exception-handler?

One way is to use the current error display handler to print the
exception, including the trace:

 (define (exception-handler exn)
    (printf "Exception caught:~n")
    ((error-display-handler) (exn-message exn) exn)
    (do-clean-up))

If you want to print the trace manually, you can extract it with
`continuation-mark-set->context' on the `continuation-marks' field of
the exception:

  (define (exception-handler exn)
    (printf "Exception caught: ~a\n~s\n" 
            exn
            (continuation-mark-set->context (exn-continuation-marks exn)))
    (do-clean-up))


Matthew



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic