Hi Jason,
Currently, the catch operator catches exceptions of type
System.Data.SqlClient.SqlException that occur in the
SqlCommand.ExecuteNonQuery() call [1]. Most likely the exception that is
thrown (and unhandled) is not of the aforementioned type.
You can append another catch statement for handling exceptions of type
System.InvalidOperationException and/or System.Exception, because they can be
thrown in certain circumstances, too.
[1] SqlCommand Documentation:
http://msdn2.microsoft.com/en-us/library/z4956bkc.aspx
--
Stanimir Stoyanov
www.stoyanoff.info
"Jason Huang" wrote:
Hi,
Would someone tell me why errors happen in TestCommand.ExecuteNonQuery and
the application just hang in there, it won't go to the catch. Why?
Thanks for help.
Jason
try
{
TestCommand[i].Transaction=myTrans;
TestCommand[i].ExecuteNonQuery();
}
catch (SqlException EQry)
{
MessageBox.Show(String.Format("An exception occurred" +
" : {0}. Please contact your system administrator.", EQry.Message));
}