Re: exception handling

new topic     » topic index » view thread      » older message » newer message

Tommy Carlier wrote:

> Above you see the finally-block: this piece of code is always called, if an
> exception occured or not. It's a place where you put code that really needs
> to be called, like closing files or releasing resources.

The 'finally' clause is the part of try/catch that I found a real pain to 
implement in my own interpreter, because it's guaranteed to *always* execute. 
For example:

   try
      ...
      return
   catch
      ...
      return
   finally
      ...
   end try

See those 'return' statements? The 'finally' clause is guaranteed to execute 
before either 'return' causes control to exit the 'try' clauses. If you have 
something like:

   try
      try
         ...
      catch
         ...
         return
      finally
         ...
      end try
   catch
      ...
   finally
      ...
   end try

Both 'finally' clauses are guaranteed to execute before the inner 'return' is 
executed. 

That's not to say that 'finally' is a bad thing - it's not! But it complicates 
the implementation of try/catch by just a bit.

-- David Cuny

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu