我有嵌套的try catch塊嵌套的try-catch與Reponse.Redirect在ASP.NET
try
{
// statements
try
{
// statements
}
catch(SqlException sqlex)
{
Response.Redirect(@"~/Error.aspx?err=" + Server.UrlEncode(sqlex.Message)
+ "&src=" + Server.UrlEncode(sqlex.ToString()));
}
catch (Exception ex)
{
Response.Redirect(@"~/Error.aspx?err=" + Server.UrlEncode(ex.Message)
+ "&src=" + Server.UrlEncode(ex.ToString()));
}
finally
{
conn.Close();
}
}
catch (Exception ex)
{
Response.Redirect(@"~/Error.aspx?err=" + Server.UrlEncode(ex.Message)
+ "&src=" + Server.UrlEncode(ex.StackTrace));
}
finally
{
conn.Close();
}
如果SqlExeception在內部第一個catch塊捕獲,然後又因爲的try ... catch包圍Response.Redirect
,由傳輸生成的ThreadAbortException被外部catch塊捕獲。
我該如何解決這個問題?謝謝!
爲什麼你需要嵌套try catch? – 2009-11-30 14:02:02