April 01, 2004 Re: what is try-catch-finally? | ||||
---|---|---|---|---|
| ||||
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
|
Copyright © 1999-2021 by the D Language Foundation