Bigloo permits to signal an error via the
error
function. Errors
may be trapped with the
try
form. Assertions allow the checking
of predicates at certain points in programs.
error proc msg obj | bigloo procedure |
This form signals an error by calling the current error handler with
proc , msg and obj as arguments.
(define (foo l)
(if (not (pair? l))
(error "foo" "argument not a pair" l)
(car l)))
(foo 4)
error--> *** ERROR:bigloo:foo:
argument not a pair -- 4
|
Switching on the -g compilation switch enables stack dumping
when the error function is invoked. That is, when a program is
compiled with -g and when, at runtime, the shell variable
BIGLOOSTACKDEPTH is set and contains a number, an execution
stack of depth BIGLOOSTACKDEPTH is printed when an error is
raised.
|
error/location proc msg obj file location | bigloo procedure |
This form signals an error by calling the current error handler with
proc , msg and obj as arguments. The error is prompted
in file , at character position location .
(define (foo l)
(if (not (pair? l))
(error/location
"foo" "argument not a pair" l "foo.scm" 115)
(car l)))
(foo 4)
error--> File "foo.scm", line 4, character 115:
# (car l)))
# ^
# *** ERROR:bigloo:foo
# argument not a pair -- 4
0. FOO
1. DYNAMIC-WIND
2. INTERP
3. ENGINE
4. MAIN
|
|
try exp handler | bigloo syntax |
The argument exp is evaluated. If an error is raised, the
handler is called. The argument handler is a procedure of
four arguments. Its first argument is the continuation of try . The
other arguments are proc , msg and obj . Invoking the
first argument will resume after the error.
(let ((handler (lambda (escape proc mes obj)
(print "***ERROR:" proc ":" mes " -- " obj)
(escape #f))))
(try (car 1) handler))
-| ***ERROR:CAR:not a pair -- 1
=> #f
|
The argument handler is not evaluated in the dynamic scope of its
try form. That is:
(let ((handler (lambda (escape proc mes obj)
(escape (car obj)))))
(try (car 1) handler))
error--> *** ERROR:bigloo:CAR
Type `PAIR' expected, `BINT' provided -- 1
|
|
Some library functions exist to help in writing handlers:
notify-error proc msg obj | bigloo procedure |
Display on error port proc , msg and obj .
|
If this variable is #t warning messages are enabled.
|
warning [arg]... | bigloo procedure |
This form signals a warning. That is, is arg are displayed
on the standard error port.
(define (foo l)
(if (not (pair? l))
(begin
(warning "foo:" "argument not a pair -- " l)
'())
(car l)))
(foo 4)
-| *** WARNING:bigloo:foo:
argument not a pair -- 4
=> '()
|
|
warning/location file location [arg]... | bigloo procedure |
This form signals a warning. That is, is arg are displayed
on the standard error port. The warning is prompted in file at
character position location .
(define (foo l)
(if (not (pair? l))
(begin
(warning/location
"foo.scm" 154 "foo:" "argument not a pair -- " l)
'())
(car l)))
(foo 4)
-| File "foo.scm", line 6, character 154:
# (car l)))
# ^
# *** WARNING:bigloo:foo:
argument not a pair -- 4
=> '()
|
|
assert (var...) s-expression | bigloo syntax |
Assertions can be enabled or disabled using Bigloo's compilation flags
-g flag to enable them). If the assertions are disabled they are
not evaluated. If an assertion is evaluated, if the expression exp
does not evaluate to #t , an error is signaled and the interpreter
is launched in an environment where var ... are bound to their
current values.
Assertion forms are legal expressions which always evaluate
to the unspecified object.
Here is an example of assertion usage:
(module foo
(eval (export foo)))
(define (foo x y)
[assert (x y) (< x y)]
(labels ((gee (t)
[assert (t) (>= t 0)]
(let ((res (+ x t)))
[assert (res t) (> res 10)]
res)))
(set! x (gee y))
[assert (x) (> x 10)]
x))
(repl)
|
This module is compiled with the -g flag to enable assertions, then
the produced executable is run:
$ a.out
1:=> (foo 1 2)
File "foo.scm", line 9, character 158:
# [assert (res t) (> res 10)]
# ^
# *** ERROR:bigloo:assert
# assertion failed -- (BEGIN (> RES 10))
0. GEE
1. FOO
-----------------------
Variables' value are :
RES : 3
T : 2
-----------------------
*:=> ^D
File "foo.scm", line 12, character 228:
# [assert (x) (> x 10)]
# ^
# *** ERROR:bigloo:assert
# assertion failed -- (BEGIN (> X 10))
0. FOO
-----------------------
Variables' value are :
X : 3
-----------------------
*:=> 3
1:=> (foo 1 2)
File "foo.scm", line 9, character 158:
# [assert (res t) (> res 10)]
# ^
# *** ERROR:bigloo:assert
# assertion failed -- (BEGIN (> RES 10))
0. GEE
1. FOO
-----------------------
Variables' value are :
RES : 3
T : 2
-----------------------
*:=>
|
|