本文介紹了捕獲的異常本身為空!的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個 ASP.NET 應用程序.一切都很好,但最近我得到了一些本身為空的異常:
I have an ASP.NET applications. Everything was fine, but recently I get exceptions that are null themselves:
try
{
// do something
}
catch (Exception ex)
{
Logger.Log("Error while tried to do something. Error: " + ex.Message);
}
有時 ex
是 null
本身!
有什么想法嗎?
推薦答案
對于到此結束的任何人,我都找到了一個可行的實例(如果只能在調試器中檢測到的話).VS2013 更新 4.
For anyone ending up here, I've found an instance where this is possible (If only detectable in the debugger). VS2013 Update 4.
try
{
// do something
}
catch (WebException ex) // <- both variables are named 'ex'
{
Logger.Log("Error while tried to do something. Error: " + ex.Message);
}
catch (Exception ex) // <- this 'ex' is null
{
Logger.Log("Error while tried to do something. Error: " + ex.Message);
}
解決方案是以不同的方式命名您的異常變量.
The solution is to name your exception variables differently.
try
{
// do something
}
catch (WebException webEx) // <- all good in the hood
{
Logger.Log("Error while tried to do something. Error: " + webEx.Message); // <-
}
catch (Exception ex) // <- this 'ex' correctly contains the exception
{
Logger.Log("Error while tried to do something. Error: " + ex.Message);
}
這篇關于捕獲的異常本身為空!的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!