Difference between finally and finalize - Coddicted

Difference between finally and finalize

finally block is used in exception handling.

 
try
{    
    //code that may or may not throw exception, goes here
}
catch(Exception e)
{
    //handling exception
}
finally
{
    //Code goes here
}
 
The finally block executes after a section of code in a method. For example, if you have code that might throw an exception, the finally block executes whether the exception is thrown or not. It is guaranteed to run.
 
The finalize method is supposed to be called before an object is garbage collected. It is not guaranteed to be called in that an object might not be garbage collected.
 
source: coderanch

Back To Top
Rate this post

Leave a Reply