[racket] Exception decorator. is it possible?

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Thu Sep 18 01:19:40 EDT 2014

 Thank you. Yet one question^ is it possible to control, what will be in stacktrace.

Because, I have (macro generated) 
(class base object%
   (define/public (write stream)
       (write-value l1 stream field1)
       (write-value l1 stream field2)
       (write-value l1 stream field3)
       ...))

Where l1 -- function, that takes its param and it to bytestream.

(class derived base
  (define/override (write stream)
     (super write stream)))

Then I have in stacktrace (super write stream), and then instantly body of l1. But no string "(write-value l1 stream field2)" where I could see, what field caouse error.
Is it possible to add it to stacktrace? Or how Racket decides, what expressions will be in stacktrace?


Wed, 17 Sep 2014 14:15:17 -0400 от Marc Burns <m4burns at uwaterloo.ca>:
>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
>


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140918/bbaa0651/attachment-0001.html>

Posted on the users mailing list.