guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reporting 'system-error informatively


From: Marius Vollmer
Subject: Re: reporting 'system-error informatively
Date: 20 Oct 2002 23:38:13 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

address@hidden (Paul Jarc) writes:

> If I catch 'system-error and display an error message, I'd like to
> include the arguments of the procedure that failed along with the
> procedure name and errno string.  Is there a way to get the arguments
> programmatically, other than by parsing the output of (backtrace)?

The arguments are passed among the arguments received by the handler.
You can do something like

    (define (call-with-error-catching thunk)
      (let ((the-last-stack #f)
            (stack-saved? #f))

        (define (handle-error key args)
          (let ((text (call-with-output-string
                       (lambda (cep)
                         (if the-last-stack
                             (display-backtrace the-last-stack cep)
                             (display "no backtrace available.\n" cep))
                         (apply display-error the-last-stack cep args)))))
            ;;; you probably need to do something else with the text.
            (gtk-show-error text)
            #f))

        (define (save-stack)
          (cond (stack-saved?)
                ((not (memq 'debug (debug-options-interface)))
                 (set! the-last-stack #f)
                 (set! stack-saved? #t))
                (else
                 (set! the-last-stack (make-stack #t lazy-dispatch 4))
                 (set! stack-saved? #t))))

        (define (lazy-dispatch key . args)
          (save-stack)
          (apply throw key args))

        (start-stack #t
                     (catch #t
                            (lambda ()
                              (lazy-catch #t
                                          thunk
                                          lazy-dispatch))
                            (lambda (key . args)
                              (if (= (length args) 4)
                                  (handle-error key args)
                                  (apply throw key args)))))))

which is probably way too complicated.  This is a weak spot of Guile,
I'm afraid.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405




reply via email to

[Prev in Thread] Current Thread [Next in Thread]