You have to write code as :
Just simple code for returns value with finally block... As finally used for cleanup resources...
if any error occurs then catch will execute and set the return value...
public bool func_a()
{
bool bFlag = true;
try
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
con.Open();
// do whatever...
bFlag = true;
}
catch (Exception ex)
{
bFlag = false;
}
finally
{
con.Close();
}
return bFlag;
"As finally used for cleanup resources so that the control cant be exit without its completion (cleanup all resources)... "
And as the finally block will always executes whatever condition error occurs or not
So we cant place two return statement in a flow... as you used in try block and then in finally block.(if no error occurred then your try code will execute then finally..so how can two return statement will works... )
--------------
It is a compile-time error for a break, continue, or goto statement to transfer control out of a finally block. When a break, continue, or goto statement occurs in a finally block, the target of the statement must be within the same finally block, or otherwise a compile-time error occurs.
From :
http://msdn.microsoft.com/en-us/library/aa664733%28v=vs.71%29.aspx[
^]
:-)