我在两个程序中生成SqlException
。
这两个过程都在同一个try catch
块中调用,具体取决于条件(一次调用)。
对于一个程序,两个错误都被捕获到正确的catch中。对于第二个程序调用..它说SqlException unhandled by usercode
。
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
ALN_VM_Cust ObjCust = new ALN_VM_Cust();
IManageVM objImanageVM = new ALN_VM_Rep();
ALN_VM_BOL ObjBOL = new ALN_VM_BOL(objImanageVM);
ObjCust.VMName = txtVMName.Text;
if(txtDescription.Value=="")
Response.Write("<script langauge=\"javascript\">alert(\"Please enter the description for configuration\");</script>");
ObjCust.VMDescription = Server.HtmlEncode(txtDescription.Value);
ObjCust.CreatedBy = Session["UserAccentureID"].ToString();
ObjCust.VMConfig = Convert.ToInt32(ddlVMConfig.SelectedValue);
ObjCust.VMCost =Convert.ToDouble( txtCost.Text);
ObjCust.Comment = Server.HtmlEncode(txtComment.Value);
if (ViewState["Mode"].ToString() == "Edit")
{
ObjCust.ModifiedBy = Session["UserAccentureID"].ToString();
ObjCust.VMId = Convert.ToInt32(ViewState["VMID"].ToString());
ObjCust.CommandType = "U";
string strResult = ObjBOL.UpdateVMDetails(ObjCust);
if (strResult == "Success")
{
ALNMessageHandler.LogEvent("VM details updated successfully", true, "VM updated");
BindGrid();
ClearFields();
}
}
}
else
{
string Result = ObjBOL.InsertVMDetails(ObjCust);
if (Result == "Success")
{
ALNMessageHandler.LogEvent("VM details saved successfully", true, "VM created");
ClearFields();
ViewState["Mode"] = "Add";
BindGrid();
}
}
}
catch (Exception ex)
{
if (ex.Message.ToString().ToUpper() == "VM NAME ALREADY EXIST.")
{
AlnErrorHandler.DisplayError(ex.Message);
}
if (ex.Message.ToString() == "Total VM cost exceeds 3000$.")
{
AlnErrorHandler.DisplayError(ex.Message);
}
//if (ex.Message.ToString().Contains("VM cannot be currently deleted") == true)
if (ex.Message.ToString() == "VM cannot be currently deleted")
{
AlnErrorHandler.DisplayError(ex.Message);
}
}
}
程序调用另一个项目的调用..
public string UpdateVMDetails(ALN_VM_Cust objCust)
{
try
{
SqlParameter[] storedParams = new SqlParameter[7];
storedParams[0] = new SqlParameter("@VMId", SqlDbType.VarChar);
storedParams[0].Value = objCust.VMId;
storedParams[1] = new SqlParameter("@VMName", SqlDbType.VarChar);
storedParams[1].Value = objCust.VMName;
storedParams[2] = new SqlParameter("@ModifiedBy", SqlDbType.VarChar);
storedParams[2].Value = objCust.ModifiedBy;
storedParams[3] = new SqlParameter("@VMDescription", SqlDbType.VarChar);
storedParams[3].Value = objCust.VMDescription;
storedParams[4] = new SqlParameter("@CommandType", SqlDbType.VarChar);
storedParams[4].Value = objCust.CommandType;
storedParams[5] = new SqlParameter("@VMCost", SqlDbType.Float);
storedParams[5].Value = objCust.VMCost;
storedParams[6] = new SqlParameter("@Comment", SqlDbType.VarChar);
storedParams[6].Value = objCust.Comment;
DataSet ds = SqlHelper.ExecuteDataset(ALNConnection, CommandType.StoredProcedure, "VM_UpdateVMDetails", storedParams);
return "Success";
}
catch (SqlException exSQL)
{
throw exSQL;
}
catch (Exception exError)
{
throw exError;
}
}
它在上面引用的其他类
的函数中最后一次捕获我哪里错了?