posted 23 years ago
Hi Neha,
I'll give it a go...
This is what I think will happen based on the following structure.
~~~
try{
//statements
}
catch{
//statements
}
finally{
//statements, possibly including another try/catch
}
//more statements here
~~~
The statements after finally will execute if
a). no exception was produced within the try block or within the finally block.
or
b). an exception was produced within try or finally, but was caught
The statements after finally won't execute if an uncaught exception is produced within try or finally.
If an exception occurs within the try block, statements in the finally block will execute regardless of whether the exception is caught. The finally block is always executed regardless of how the try block is exited (eg. via return, break, continue, or just by reaching the end of the try block). It's meant to be a guaranteed way to clean up before exiting a method.
If an exception occurs within the try block and is not caught, finally will still execute, but the statements following finally will not execute.
If try has not produced an uncaught exception but if the finally block produces an uncaught exception, the code following the finally block will not execute.
If no exception occurs prior to the statements following finally, they will execute (following execution of the statements within the finally block).
I don't know of a website, but here's a concise summary from one of my text books of terms used in exception handling
try
~~~
This defines a block of statements that may throw an exception. If an exception is thrown, an optional catch block can handle specific exceptions thrown within the try block. Also, an optional finally block will be executed regardless of whether an exception is thrown or not.
catch
~~~
This is used to declare a block of statements to be executed in the event that an exception, or a run-time error occurs in a preceeding try block.
throw
~~~
This allows the user to throw an exception or any class that implements the throwable interface.
throws
~~~
This keyword is used in method declarations that specify which exceptions are not handled within the method, but rather passed to the next higher level of the program.
finally
~~~
This executes a block of statements regardless or whether an exception or a run-time error occurred in a block defined previously by the try keyword
cheerio
rowan