slot-ref, slot-set! et al bypass "using-class" variants
[bpt/guile.git] / module / ice-9 / stack-catch.scm
CommitLineData
0109c4bf
MD
1;;; installed-scm-file
2
fede5c89 3;;;; Copyright (C) 2001, 2006, 2010 Free Software Foundation, Inc.
0109c4bf 4;;;;
73be1d9e
MV
5;;;; This library is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU Lesser General Public
7;;;; License as published by the Free Software Foundation; either
53befeb7 8;;;; version 3 of the License, or (at your option) any later version.
0109c4bf 9;;;;
73be1d9e 10;;;; This library is distributed in the hope that it will be useful,
0109c4bf 11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;;; Lesser General Public License for more details.
0109c4bf 14;;;;
73be1d9e
MV
15;;;; You should have received a copy of the GNU Lesser General Public
16;;;; License along with this library; if not, write to the Free Software
92205699 17;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0109c4bf
MD
18;;;;
19
20(define-module (ice-9 stack-catch)
d8158b83 21 #:use-module (ice-9 save-stack)
fede5c89 22 #:export (stack-catch))
0109c4bf
MD
23
24(define (stack-catch key thunk handler)
25 "Like @code{catch}, invoke @var{thunk} in the dynamic context of
26@var{handler} for exceptions matching @var{key}, but also save the
27current stack state in the @var{the-last-stack} fluid, for the purpose
28of debugging or re-throwing of an error. If thunk throws to the
29symbol @var{key}, then @var{handler} is invoked this way:\n
30@example
56658166 31 (handler key args ...)
0109c4bf
MD
32@end example\n
33@var{key} is a symbol or #t.\n
34@var{thunk} takes no arguments. If @var{thunk} returns normally, that
35is the return value of @code{catch}.\n
36Handler is invoked outside the scope of its own @code{catch}. If
37@var{handler} again throws to the same key, a new handler from further
38up the call chain is invoked.\n
39If the key is @code{#t}, then a throw to @emph{any} symbol will match
40this call to @code{catch}."
41 (catch key
56658166
NJ
42 thunk
43 handler
fede5c89
AW
44 (lambda (key . args)
45 ;; Narrow by two more frames: this one, and the throw handler.
46 (save-stack 2)
47 (apply throw key args))))