On 10-Sep-2002 John Klein wrote:
> I have a question about obtaining a backtrace when
> catching errors.
> 
> consider the following snippet of code:
> 
> ;;;;;;;;;;;;;;;;;;;
> (defun top ()
>   (multiple-value-bind (ret err) (ignore-errors (foo))
>     (when err (format t "Got error <~A>~%" err))
>     ;; HERE
>     ret))
> 
> (defun foo () (bar 0))
> (defun bar (x) (/ 1 x)) ;; bar causes an error for x=0
> ;;;;;;;;;;;;;;;;;;;
> 
> This catches and prints a division by 0 error when (top)
> is evaluated.
> 
> But is there some way to obtain a backtrace leading to
> the error (eg, to a string) at the location denoted by "HERE"?
> This would be very useful for diagnosing infrequent errors
> in server apps, eg.

It will not work with ignore-errors, but CL has better methods for this.
If you do handler-bind, a function is invoked for the error with all the 
stack when it occurs. In this method you should be able to collect the 
stacktrace, and then to invoke a restart.

        Martin

-- 
+-[Martin Ginkel]--------------[mailto:ginkel(at)mpi-magdeburg.mpg.de]-+
| MPI Magdeburg, Zi S2.09    Sandtorstr. 1, D-39106 Magdeburg, Germany |
| people who expect nothing (positive), will never be dissappointed    |
+-[tel/fax: +49 391 6110 482/529]----[http://www.mpi-magdeburg.mpg.de]-+

Reply via email to