| GNU Octave Manual by John W. Eaton Paperback (6"x9"), 324 pages, 4 figures ISBN 0954161726 RRP £19.99 ($29.99) |
10.8 The try Statement
In addition to unwind_protect, Octave supports another limited form of exception handling.
The general form of a try block looks like this:
try body catch cleanup end_try_catch
Where body and cleanup are both optional and may contain any Octave expressions or commands. The statements in cleanup are only executed if an error occurs in body.
No warnings or error messages are printed while body is
executing. If an error does occur during the execution of body,
cleanup can access the text of the message that would have been
printed in the builtin constant __error_text__. This is the same
as eval (try, catch) (which may now also use
__error_text__) but it is more efficient since the commands do
not need to be parsed each time the try and catch statements
are evaluated. See section 12 Error Handling, for more information about the
__error_text__ variable.
Octave's try block is a very limited variation on the Lisp condition-case form (limited because it cannot handle different classes of errors separately). Perhaps at some point Octave can have some sort of classification of errors and try-catch can be improved to be as powerful as condition-case in Lisp.
| ISBN 0954161726 | GNU Octave Manual | See the print edition |