Finally block

In Java, does the finally block get executed if we insert a return statement inside the try block of a try-catch-finally?

Yes, it will get executed. The finally block gets executed when the try block exists. Even when we attempt to exit within the try block(via a return statement, a continue statement, a break statement or any exception), the finally block will still be executed.

Note that there are some cases in which the finally block will not get executed, such as the following:

1. If the virtual machine exits during try/catch block execution.

2.If the thread which is executing the try/catch block gets killed.

This entry was posted in JAVA. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s