1. Re: exception handling
- Posted by David <dcuny at lanset.com> Aug 25, 2004
- 407 views
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