The finally keyword is used to define a block that is always executed in a tryâcatchâfinally statement.
A finally block typically contains cleanup code that recovers from partial execution of a try block.
If any portion of the try block is executed, the code in a finally block is always guaranteed to be executed whether an exception occurs or not and independent of whether the try or catch blocks contain return, continue or break statements.
Syntax:try
{
}
catch ( e)
{
}
finally
{
}
Example:try
{
// code that throws an exception
int zero = 0;
Console.WriteLine("In try block: attempting division by zero");
int myInt = 1 / zero; // throws the exception
Console.WriteLine("You never see this message!");
}
catch
{
// code that handles the exception
Console.WriteLine("In catch block: an exception was thrown");
}
finally
{
// code that does any cleaning up
Console.WriteLine("In finally block: do any cleaning up here");
}
License.
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 248 / 158778262. Delta: 0.00290 с