How are try, catch and finally block organized?

How are try, catch and finally block organized?

The try block is the region of code where exceptions can get produced. So most of the code of execution lies in this region.

The catch block is where an Exception is caught. Then, the action to be performed upon catching the exception is stated in this block. Usually a user friendly message is displayed.

The finally block is the region where the code that needs to be executed under any circumstance is written. This is usually performing a clean up. Eg: Freeing the resources, etc.

If the finally clause executes a return statement, it overrides a thrown exception (so the exception will not be thrown; instead the return will occur).
What is a throw in an Exception block?
What is a throw in an Exception block? - The different ways to use a throw are:...
What are Chained Exceptions?
What are Chained Exceptions? - When an application responds to an exception by throwing another exception, it is very useful to know when an exception caused another...
What is the purpose of the finally clause of a try-catch-finally statement?
Purpose of the finally clause - The finally block is the region where the code that needs to be executed under any circumstance is written...
Post your comment