stack-catch.scm 1.8 KB

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