On Sep 10, 6:21 am, Fang Zhen <[email protected]> wrote:
> Hi Everyone,
>
> In Page 35 of javaexceptions.sxi of Exception Handling section, it wrote:
>
> Block of code is always executed despite of different scenarios:
> Forced exit occurs using a return, a continue or a break statement
> Normal completion
> Caught exception thrown
> Exception was thrown and caught in the method
> Uncaught exception thrown
> Exception thrown was not specified in any catch block in the method
>
> My question:
> Since Compiling error like "unreported exception java.lang.Exception; must
> be caught or declared to be thrown" would be shown and build would fail, why
> it's said "Block of code is always executed despite of Uncaught exception
> thrown" ?
It explains the finally keyword, so you have reported the exception as
normal: i.e. you have either caught it or declared it to be thrown,
but if you use the finally keyword, the block of code inside finally
braces is always executed.
This is use, in particular, when you open a stream, and an exception
occurs, perhaps because the underlying file is not found, then the
finally block allows you to close the stream before the program ends.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---