[ << ] | [ < ] | [ 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-handler
towith-exception-handler
because the former provides better debugging support and because its semantics is more intuitive.
- 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-handler
form is the value produced by invoking the handler. The handler is executed in the continuation of thewith-handler
form.JVM note: When executed within a JVM, the form
with-handler
also catches Java exceptions.Important note: Since Bigloo version 3.2c, error handlers are executed after the execution stack is unwound. Hence, error handlers are executed after protected blocks. For instance in the following code:
(with-handler (lambda (e) action) (unwind-protect body protect))
The action is executed after 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:
-
&exception
which is defined as:(class &exception (fname read-only (default #f)) (location read-only (default #f)))
-
&error
defined as:(class &error::&exception (proc read-only) (msg read-only) (obj read-only))
-
&type-error
defined as:(class &type-error::&error (type read-only))
-
&io-error
defined as:(class &io-error::&error)
-
&io-port-error
defined as:(class &io-port-error::&io-error)
-
&io-read-error
defined as:(class &io-read-error::&io-port-error)
-
&io-write-error
defined as:(class &io-write-error::&io-port-error)
-
&io-closed-error
defined as:(class &io-closed-error::&io-port-error)
-
&io-file-not-found-error
defined as:(class &io-file-not-found-error::&io-error)
-
&io-parse-error
defined as:(class &io-parse-error::&io-error)
-
&io-unknown-host-error
defined as:(class &io-unknown-host-error::&io-error)
-
&io-malformed-url-error
defined as:(class &io-malformed-url-error::&io-error)
-
&http-error
defined as:(class &http-error::&error)
-
&http-redirection-error
defined as:(class &http-redirection-error::&http-error)
-
&http-status-error
defined as:(class &http-status-error::&http-error)
-
&http-redirection
defined as:(class &http-redirection::&exception (port::input-port read-only) (url::bstring read-only))
-
&process-exception
defined as:(class &process-exception::&error)
-
&warning
defined as:(class &warning::&exception (args read-only))
-
&eval-warning
defined as:(class &warning::&warning)
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.