为什么我的try catch不能捕捉错误??
现在我将添加更新记录的方法统一写在一个类里面,方便以后调用,但为什么try能生效,catch就没有反应,为何,try catch到底要怎么用,谢谢!
public int Execute(string SqlCommand)
{
int count = 0;
bool open = this.IsOpen;
if (!open)
this.Open();
SqlCommand cmd = new SqlCommand(SqlCommand, this.conn);
count = cmd.ExecuteNonQuery();
try
{
count = cmd.ExecuteNonQuery();
System.Web.HttpContext.Current.Response.Write("<script>alert('操作成功!');</script>");
}
catch (System.FormatException E)
{
System.Web.HttpContext.Current.Response.Write(E.Message);
System.Web.HttpContext.Current.Response.Write(SqlCommand);
System.Web.HttpContext.Current.Response.Write("<script langeuage=javascript>alert('SQL语句有问题啊老大!');</script>");
}
if (!open)
this.Close();
return count;
}