Mercurial > hg > octave-nkf
changeset 18220:6fd22474783e stable
doc: Update manual for "catch err" syntax (bug #33217)
author | Felipe G. Nievinski <fgnievinski@gmail.com> |
---|---|
date | Sun, 05 Jan 2014 15:32:24 -0200 |
parents | a8408a424a37 |
children | 03226f218077 64f178d8e1e0 |
files | doc/interpreter/errors.txi doc/interpreter/stmt.txi |
diffstat | 2 files changed, 42 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/errors.txi +++ b/doc/interpreter/errors.txi @@ -176,6 +176,22 @@ @end group @end example +@noindent +Alternatively, the output of the @code{lasterror} function can be found +in a variable indicated immediately after the @code{catch} keyword, as +in the example below showing how to redirect an error as a warning: + +@example +@group +try + @dots{} +catch err + warning(err.identifier, err.message); + @dots{} +end_try_catch +@end group +@end example + @DOCSTRING(lasterror) @DOCSTRING(lasterr)
--- a/doc/interpreter/stmt.txi +++ b/doc/interpreter/stmt.txi @@ -815,16 +815,17 @@ point of the error and the statement to restore the value would not be executed. +In addition to unwind_protect, Octave supports another form of +exception handling, the @code{try} block. + + @node The try Statement @section The try Statement @cindex @code{try} statement @cindex @code{catch} @cindex @code{end_try_catch} -In addition to unwind_protect, Octave supports another limited form of -exception handling. - -The general form of a @code{try} block looks like this: +The original form of a @code{try} block looks like this: @example @group @@ -841,14 +842,27 @@ Octave expressions or commands. The statements in @var{cleanup} are only executed if an error occurs in @var{body}. -No warnings or error messages are printed while @var{body} is -executing. If an error does occur during the execution of @var{body}, -@var{cleanup} can use the function @code{lasterr} to access the text -of the message that would have been printed. This is the same -as @code{eval (@var{try}, @var{catch})} but it is more efficient since -the commands do not need to be parsed each time the @var{try} and -@var{catch} statements are evaluated. @xref{Errors and Warnings}, for more -information about the @code{lasterr} function. +No warnings or error messages are printed while @var{body} is executing. +If an error does occur during the execution of @var{body}, @var{cleanup} +can use the functions @code{lasterr} or @code{lasterror} to access the +text of the message that would have been printed, as well as its +identifier. The alternative form, + +@example +@group +try + @var{body} +catch @var{err} + @var{cleanup} +end_try_catch +@end group +@end example + +@noindent +will automatically store the output of @code{lasterror} in the structure +@var{err}. @xref{Errors and Warnings} for more information about the +@code{lasterr} and @code{lasterror} functions. + @node Continuation Lines @section Continuation Lines