| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
16.2 Exceptions
- SRFI-18 function: current-exception-handler
Returns the current exception handler with is a 0-ary procedure.
- SRFI-18 function: with-exception-handler handler thunk
Returns the result(s) of calling thunk with no arguments. The handler, which must be a procedure, is installed as the current exception handler in the dynamic environment in effect during the call to thunk. When possible, prefer
with-handlertowith-exception-handlerbecause the former is more efficient than the latter.
- bigloo form: with-handler handler body
Returns the result(s) of evaluating body. The handler, which must be a procedure, is installed as the current exception handler in the dynamic environment in effect during the evaluation of body. Contrarily to
with-exception-handler, if an exception is raised, the handler is invoked and the value of thewith-handlerform is the value produced by invoking the handler.JVM note: When executed within a JVM, the form
with-handleralso catches Java exceptions.The form
with-handleris intrinsically more efficient than the functionwith-exception-handler. From a semantics point of view,with-handlercould be re-written in terms ofwith-exception-handlersuch as:(with-handler handler1 body1) ≡ (bind-exit (exit) (with-exception-handler (lambda (e) (exit (handler1 e))) (lambda () body)))It should be noted that the error handler is executed before the execution stack is unwound. Hence, error handlers are executed before protected blocks. For instance in the following code:
(with-handler (lambda (e) action) (unwind-protect body protect))The action is executed before protect.
- SRFI-18 function: raise obj
Calls the current exception handler with obj as the single argument. obj may be any Scheme object. Note that invoking the current handler does not escape from the current computation. It is up the to handler to perform the escape. It an error, signaled by the runtime system, if the current exception handler returns.
(define (f n) (if (< n 0) (raise "negative arg") (sqrt n)))) (define (g) (bind-exit (return) (with-exception-handler (lambda (exc) (return (if (string? exc) (string-append "error: " exc) "unknown error"))) (lambda () (write (f 4.)) (write (f -1.)) (write (f 9.)))))) (g) -| 2. and returns "error: negative arg"
The standard Bigloo runtime system uses the following classes for signaling errors and warnings:
-
&exceptionwhich is defined as:(class &exception (fname read-only (default #f)) (location read-only (default #f)))
-
&errordefined as:(class &error::&exception (proc read-only) (msg read-only) (obj read-only))
-
&type-errordefined as:(class &type-error::&error (type read-only))
-
&io-errordefined as:(class &io-error::&error)
-
&io-port-errordefined as:(class &io-port-error::&io-error)
-
&io-read-errordefined as:(class &io-read-error::&io-port-error)
-
&io-write-errordefined as:(class &io-write-error::&io-port-error)
-
&io-closed-errordefined as:(class &io-closed-error::&io-port-error)
-
&io-file-not-found-errordefined as:(class &io-file-not-found-error::&io-error)
-
&io-parse-errordefined as:(class &io-parse-error::&io-error)
-
&io-unknown-host-errordefined as:(class &io-unknown-host-error::&io-error)
-
&io-malformed-url-errordefined as:(class &io-malformed-url-error::&io-error)
-
&http-errordefined as:(class &http-error::&error)
-
&http-redirection-errordefined as:(class &http-redirection-error::&http-error)
-
&http-status-errordefined as:(class &http-status-error::&http-error)
-
&http-redirectiondefined as:(class &http-redirection::&exception (port::input-port read-only) (url::bstring read-only))
-
&process-exceptiondefined as:(class &process-exception::&error)
-
&warningdefined as:(class &warning::&exception (args read-only))
-
&eval-warningdefined as:(class &warning::&warning)
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
