3
<title>The try Statement - Untitled</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="Untitled">
6
<meta name="generator" content="makeinfo 4.11">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="Statements.html#Statements" title="Statements">
9
<link rel="prev" href="The-unwind_005fprotect-Statement.html#The-unwind_005fprotect-Statement" title="The unwind_protect Statement">
10
<link rel="next" href="Continuation-Lines.html#Continuation-Lines" title="Continuation Lines">
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12
<meta http-equiv="Content-Style-Type" content="text/css">
13
<style type="text/css"><!--
14
pre.display { font-family:inherit }
15
pre.format { font-family:inherit }
16
pre.smalldisplay { font-family:inherit; font-size:smaller }
17
pre.smallformat { font-family:inherit; font-size:smaller }
18
pre.smallexample { font-size:smaller }
19
pre.smalllisp { font-size:smaller }
20
span.sc { font-variant:small-caps }
21
span.roman { font-family:serif; font-weight:normal; }
22
span.sansserif { font-family:sans-serif; font-weight:normal; }
28
<a name="The-try-Statement"></a>
29
Next: <a rel="next" accesskey="n" href="Continuation-Lines.html#Continuation-Lines">Continuation Lines</a>,
30
Previous: <a rel="previous" accesskey="p" href="The-unwind_005fprotect-Statement.html#The-unwind_005fprotect-Statement">The unwind_protect Statement</a>,
31
Up: <a rel="up" accesskey="u" href="Statements.html#Statements">Statements</a>
35
<h3 class="section">10.9 The <code>try</code> Statement</h3>
37
<p><a name="index-g_t_0040code_007btry_007d-statement-554"></a><a name="index-g_t_0040code_007bcatch_007d-555"></a><a name="index-g_t_0040code_007bend_005ftry_005fcatch_007d-556"></a>
38
In addition to unwind_protect, Octave supports another limited form of
41
<p>The general form of a <code>try</code> block looks like this:
43
<pre class="example"> try
49
<p class="noindent">where <var>body</var> and <var>cleanup</var> are both optional and may contain any
50
Octave expressions or commands. The statements in <var>cleanup</var> are
51
only executed if an error occurs in <var>body</var>.
53
<p>No warnings or error messages are printed while <var>body</var> is
54
executing. If an error does occur during the execution of <var>body</var>,
55
<var>cleanup</var> can use the function <code>lasterr</code> to access the text
56
of the message that would have been printed. This is the same
57
as <code>eval (</code><var>try</var><code>, </code><var>catch</var><code>)</code> but it is more efficient since
58
the commands do not need to be parsed each time the <var>try</var> and
59
<var>catch</var> statements are evaluated. See <a href="Errors-and-Warnings.html#Errors-and-Warnings">Errors and Warnings</a>, for more
60
information about the <code>lasterr</code> function.
62
<p><a name="index-continuation-lines-557"></a><a name="index-g_t_0040code_007b_002e_002e_002e_007d-continuation-marker-558"></a><a name="index-g_t_0040code_007b_005c_007d-continuation-marker-559"></a>