Thursday, 9 January 2014

Usage of Finally block

Classic example is closing a database connection
no matter whether the SQL operation was successful or generated an exception.
In such a case, you can use the optional
finally block

try
{
// Open a database connection
// Execute SQL statement
}
catch (DbException ex)
{
// Handle database exception
}
finally
{
// Close database connection if it exists
}

1 comment: