1.

What Is Finally Block?

Answer»

When an exception occurs in the code, the flow of the execution may change or even end ABRUPTLY. That may cause problem if some resources were OPENED in the method. 

As exp if a file was opened in a method and it was not closed in the end as some exception occurred then the resources may remain open CONSUMING memory. finally PROVIDES that exception-handling mechanism to clean up.

Code with in the finally block will be executed after a try/catch block has completed. The finally block will be executed whether or not an exception is thrown.

When an exception occurs in the code, the flow of the execution may change or even end abruptly. That may cause problem if some resources were opened in the method. 

As exp if a file was opened in a method and it was not closed in the end as some exception occurred then the resources may remain open consuming memory. finally provides that exception-handling mechanism to clean up.

Code with in the finally block will be executed after a try/catch block has completed. The finally block will be executed whether or not an exception is thrown.



Discussion

No Comment Found