/
html/
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ProgrammersManual.texinfo on 4 March 1997 -->

<TITLE>LambdaMOO Programmer's Manual - Finally</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_35.html">previous</A>, <A HREF="ProgrammersManual_37.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
<P><HR><P>


<H3><A NAME="SEC36" HREF="ProgrammersManual_toc.html#TOC36">Cleaning Up After Errors</A></H3>

<P>
Whenever an error is raised, it is usually the case that at least some MOO code
gets skipped over and never executed.  Sometimes, it's important that a piece
of code <EM>always</EM> be executed, whether or not an error is raised.  Use the
<CODE>try</CODE>-<CODE>finally</CODE> statement for these cases; it has the following
syntax:

</P>

<PRE>
try
  <VAR>statements-1</VAR>
finally
  <VAR>statements-2</VAR>
endtry
</PRE>

<P>
First, <VAR>statements-1</VAR> is executed; if it completes without raising an
error, returning from this verb, or terminating the current iteration of a
surrounding loop (we call these possibilities <STRONG>transferring control</STRONG>), then
<VAR>statements-2</VAR> is executed and that's all that happens for the entire
<CODE>try</CODE>-<CODE>finally</CODE> statement.

</P>
<P>
Otherwise, the process of transferring control is interrupted and
<VAR>statments-2</VAR> is executed.  If <VAR>statements-2</VAR> itself completes without
transferring control, then the interrupted control transfer is resumed just
where it left off.  If <VAR>statements-2</VAR> does transfer control, then the
interrupted transfer is simply forgotten in favor of the new one.

</P>
<P>
In short, this statement ensures that <VAR>statements-2</VAR> is executed after
control leaves <VAR>statements-1</VAR> for whatever reason; it can thus be used to
make sure that some piece of cleanup code is run even if <VAR>statements-1</VAR>
doesn't simply run normally to completion.

</P>
<P>
Here's an example:

</P>

<PRE>
try
  start = time();
  object:(command)(@arguments);
finally
  end = time();
  this:charge_user_for_seconds(player, end - start);
endtry
</PRE>

<P><HR><P>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_35.html">previous</A>, <A HREF="ProgrammersManual_37.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
</BODY>
</HTML>