No, it will not.
Please check the difference between how these two samples work:
try
{
Console.WriteLine ("try");
throw (new Exception ("throw in try"));
}
catch (Exception e)
{
Console.WriteLine ("catch");
throw;
}
finally
{
Console.WriteLine ("finally");
}
and
try
{
Console.WriteLine ("try");
throw (new Exception ("throw in try"));
}
catch (Exception e)
{
Console.WriteLine ("catch");
}
finally
{
Console.WriteLine ("finally");
}
the "throw" in the catch block causes another exception to be thrown. The
finally block refers only to exceptions and handling the flow related to the
try block. The exception from the catch block would have to be handled on
the outside like:
try
{
Console.WriteLine ("try 2");
try
{
Console.WriteLine ("try");
throw (new Exception ("throw in try"));
}
catch (Exception e)
{
Console.WriteLine ("catch");
throw;
}
finally
{
Console.WriteLine ("finally");
}
}
catch
{
Console.WriteLine ("catch 2");
}
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply
"Kevin Jackson" <so*****@covad.net> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
In the following code snippet, will the finally block be executed when the
throw is executed in the catch block???? I'm assuming it will.
catch (Exception e)
{
// if (ContextUtil.IsInTransaction)ContextUtil.SetAbort( );
ReportError objError = new ReportError();
objError.PersistError(e,null,"DBWrite:executeStore dProcedureReturnXML","Conn ectionString = " + m_sqlConnectionString + " : blnClearFlag=" +
blnClearFlag + " : Stored Proc Name=" + storedProcedureName + " : Element Name=" +
elementName);
throw;
}
finally
{
cnConnection.Close();
cnConnection.Dispose();
blnClearFlag = true;
}