April 01, 2004 Re: what is try-catch-finally? | ||||
---|---|---|---|---|
| ||||
On Wed, 31 Mar 2004 21:48:20 -0800, Andy Friesen <andy@ikagames.com> wrote:
> Karl Bochert wrote:
> >>
> >> try { <some statement(s) }
> >> catch (<errorclass>) { <do something about it> }
> >> finally { <always run> };
> >>
> >
> > How does that differ from:
> >
> > try { <some statement(s) }
> > catch (<errorclass>) { <do something about it> }
> > <always run>};
>
> Even if an exception is thrown, and isn't caught in this scope, the finally block will execute while the stack is being unwound.
>
> ie
>
> try {
> throw new Exception("This won't be caught here.");
> } catch (IOError error) {
> we can't catch Exception() here, only IOError
> } finally {
> // clean up the file, whether or not an error occurred
> myFile.close();
> }
>
> -- andy
Makes sense -- sort of interleaved exceptions
Not for me, I think
KtB
|
Copyright © 1999-2021 by the D Language Foundation