comparison doc/interpreter/stmt.txi @ 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 d63878346099
children faf32a725693
comparison
equal deleted inserted replaced
18219:a8408a424a37 18220:6fd22474783e
813 would not be restored if an error occurs while evaluating the first part 813 would not be restored if an error occurs while evaluating the first part
814 of the @code{unwind_protect} block because evaluation would stop at the 814 of the @code{unwind_protect} block because evaluation would stop at the
815 point of the error and the statement to restore the value would not be 815 point of the error and the statement to restore the value would not be
816 executed. 816 executed.
817 817
818 In addition to unwind_protect, Octave supports another form of
819 exception handling, the @code{try} block.
820
821
818 @node The try Statement 822 @node The try Statement
819 @section The try Statement 823 @section The try Statement
820 @cindex @code{try} statement 824 @cindex @code{try} statement
821 @cindex @code{catch} 825 @cindex @code{catch}
822 @cindex @code{end_try_catch} 826 @cindex @code{end_try_catch}
823 827
824 In addition to unwind_protect, Octave supports another limited form of 828 The original form of a @code{try} block looks like this:
825 exception handling.
826
827 The general form of a @code{try} block looks like this:
828 829
829 @example 830 @example
830 @group 831 @group
831 try 832 try
832 @var{body} 833 @var{body}
839 @noindent 840 @noindent
840 where @var{body} and @var{cleanup} are both optional and may contain any 841 where @var{body} and @var{cleanup} are both optional and may contain any
841 Octave expressions or commands. The statements in @var{cleanup} are 842 Octave expressions or commands. The statements in @var{cleanup} are
842 only executed if an error occurs in @var{body}. 843 only executed if an error occurs in @var{body}.
843 844
844 No warnings or error messages are printed while @var{body} is 845 No warnings or error messages are printed while @var{body} is executing.
845 executing. If an error does occur during the execution of @var{body}, 846 If an error does occur during the execution of @var{body}, @var{cleanup}
846 @var{cleanup} can use the function @code{lasterr} to access the text 847 can use the functions @code{lasterr} or @code{lasterror} to access the
847 of the message that would have been printed. This is the same 848 text of the message that would have been printed, as well as its
848 as @code{eval (@var{try}, @var{catch})} but it is more efficient since 849 identifier. The alternative form,
849 the commands do not need to be parsed each time the @var{try} and 850
850 @var{catch} statements are evaluated. @xref{Errors and Warnings}, for more 851 @example
851 information about the @code{lasterr} function. 852 @group
853 try
854 @var{body}
855 catch @var{err}
856 @var{cleanup}
857 end_try_catch
858 @end group
859 @end example
860
861 @noindent
862 will automatically store the output of @code{lasterror} in the structure
863 @var{err}. @xref{Errors and Warnings} for more information about the
864 @code{lasterr} and @code{lasterror} functions.
865
852 866
853 @node Continuation Lines 867 @node Continuation Lines
854 @section Continuation Lines 868 @section Continuation Lines
855 @cindex continuation lines 869 @cindex continuation lines
856 @cindex @code{...} continuation marker 870 @cindex @code{...} continuation marker