Lisp language configured for easy creation of programs from data. To verify that created the program worked, sometimes the only solution is to run the program. When an error occurs in the program up a system check (the exception). If after calculating the problem check exception raised, then you can run other tasks for the error restoration.
Function try runs the task. When an exception is checked the error code. Check with the command eq, that is, identity.
(nil try (nil eval task) out-of-memory (cout writeln "Out of memory") nil (cout writeln "Task " task " is wrong"))
The error may be a symbol, a list or other specified by command throw. The latest error code can be nil, to intercept all exceptions. To find out what went wrong, you can use the function exception.
(nil try (nil eval task) nil (cout writeln "Exception is " (nil exception)))
As an example of using could serve the function of add numbers to the vector. If you receive an error function does not know what to do and sends a signal to function that caused it.
('vector defmethod add-number (x n)
(nil if (nil numberp x)
(nil if (nil numberp n)
(nil try (this push x n)
nil (nil throw 'out-of-memory))
(nil throw 'syntax))
(nil throw 'syntax)))
(nil setq v ('vector newobject))
(nil try (v add-number "1")
nil (cout writeln "error: " (nil exception)))
(nil try (v add-number 1 1e10)
nil (cout writeln "error: " (nil exception)))
The result will be error output syntax and out-of-memory.
The most important aspect of debugging programs is to derive the history of computing at the time when an exception is identified. History can be obtained by using (nil exception-history). History is defined as a list (… (integer-number-depth-computing-in-stack bool-input/output command) …). To view can call the function (stream history-show (nil exception-history)).
Suppose you have a simple function collapses to access elements of a vector.
('vector defmethod element (i)
(nil if (nil and (i >= 0) (i < (this size)))
(this elt i)))
After futile attempts to debug a program you write a output of calculation history.
(nil try (vector element i) nil (cout history-show (nil exception-history)))
The result of the history writing is always impressive.
inp< (this elt i) inp< this out> #(a b c) inp< (#(a b c) elt i) inp< (#(a b c) BIM(vector,elt) i) inp< i out> 2.5 inp< (#(a b c) BIM(vector,elt) 2.5) out> nil out> nil out> nil