[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
`try' exception handler
From: |
Keisuke Nishida |
Subject: |
`try' exception handler |
Date: |
Thu, 19 Apr 2001 22:47:55 -0400 |
User-agent: |
Wanderlust/2.4.0 (Rio) SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) Emacs/21.0.102 (i686-pc-linux-gnu) MULE/5.0 (SAKAKI) |
The module below is a `try'-style exception handler,
which can be used like this:
(try foo
((misc-error . args) 'misc)
((unbound-variable . args) 'unbound)) => unbound
Should this be included in ice-9?
Keisuke
------------------------------------------------------------------------
(define-module (ice-9 try)
:use-module (ice-9 stack-catch)
:export (try stack-catch))
(define-macro (try exp . with)
`(stack-catch #t
(lambda () ,exp)
(lambda (key . args)
(case key
,@(map (lambda (clause)
(if (or (not (pair? clause)) (not (pair? (car clause))))
(error "bad clause:" clause)
`((,(caar clause))
(apply (lambda ,(cdar clause) ,@(cdr clause)) args))))
with)
(else
(apply throw key args))))))
- `try' exception handler,
Keisuke Nishida <=