我已经解决了这个问题,我发布了。区分原始System.Exception并抛出新的Exception/ApplicationException?
对于疯狂调用的方法,是否可以区分原始System.Exception(即throw ex;
)和新的Exception(即throw new Exception("Specific error", ex);
)还是新的ApplicationException
?
public void InsertNewCar()
{
try
{
Car myCar = new Car();
myCar.Insert();
}
catch (Exception ex)
{
if (/* This ex is the New Exception */
alert(somethingMissingMsg);
}
else /* This is the original exception */
{
alert(Something wrong generic error);
}
}
public void Insert()
{
try
{
SqlHelper.ExecuteNonQuery(ConnString, CommandType.Text, sqlInsert);
}
catch (SqlException ex)
{
if (ex.Number == 515)
{
throw new Exception("Missing something", ex);
//throw new ApplicationException("Missing something", ex);
}
else
{
throw ex;
}
}
}
谢谢。
[订购catch块时,试图处理异常(可能的重复http://stackoverflow.com/questions/15609597/order-catch-blocks-when-try-to-handle-an-exception )@Stephen – Stephen
,这不是重复的。订购catch块如何与此相关?我的问题与实际异常无关,但如何区分接收异常的方法中的异常。 – rbhat
我刚才明白你的问题....阅读对方的回答评论后... – Stephen