[racket] Exception decorator. is it possible?

From: Marc Burns (m4burns at uwaterloo.ca)
Date: Wed Sep 17 14:15:17 EDT 2014

It's not generally possible to edit the message contained in an
exception. However, you can add information to the program's stack using
continuation marks. Here's an example:

(define my-cont-mark-key (gensym))

(define (parse-item item)
  (with-continuation-mark my-cont-mark-key item
    ...))

(with-handlers
  ([exn? (lambda(e)
           ((error-display-handler)
            (format "Parser exception at item ~a:\n~a"
                    (first
                      (continuation-mark-set->list
                        (exn-continuation-marks e)
                        my-cont-mark-key))
                    (exn-message e))
            e))])
  (parse-item start-item))

The exception captures the continuation marks installed when it is
thrown. You can extract the information you added to the stack with 
these marks in the exception handler.

On Wed, Sep 17, 2014 at 08:59:15PM +0400, Roman Klochkov wrote:
>  I'm writeing a parser.
> So I want to see in parser exception what happend and when (not only where).
> 
> (define (parse-item item)
> ?? ??(with-handlers ([exn? (lambda (e) (raise (struct-copy exn e [message (format "At item ~a\n~a" item (exn-message e))])))])
> ?? ?? ?? ?? ??....))
> 
> But this way I lose all exception types. Is there a way to change exception message, saving its type, except long copy/paste like
> (with-handlers ([exn:fail:contract:arity? (raise (struct-copy exn:fail:contract:arity ...))]
> ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??[exn:fil:contract? (raise??(struct-copy exn:fail:contract ...))]
> ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??...) 
> ?? ??...)
> 
> ?
> 
> -- 
> Roman Klochkov

> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.