在我的 asp.net 應用程序中,如果應用程序拋出異常,它會被捕獲并改為提供 500 頁。我想在拋出位置中斷調(diào)試器。目前我正在使用以下代碼片段: void ExceptionHandler(Exception ex) { if (Debugger.IsAttached) { Debugger.Break(); }}然而,這段代碼在ExceptionHandler,而不是在拋出位置中斷。我怎樣才能在投擲位置打破?我不想更改異常設置,因為我想中斷達到的異常ExceptionHandler,而不是系統(tǒng)從中恢復的異常。為了更好地說明我的問題:class Server // Server owned by third party{ static void Main(string[] args) { AppDomain.CurrentDomain.FirstChanceException += (source, e) => { // This does not help, because there are legit exceptions Console.WriteLine("FirstChanceException event raised in {0}: \"{1}\"", AppDomain.CurrentDomain.FriendlyName, e.Exception.Message); }; AppDomain.CurrentDomain.UnhandledException += (source, e) => { // This does not help, because exception should be handled by server, otherwise it would shut down Console.WriteLine("UnhandledException event raised in {0}: \"{1}\"", AppDomain.CurrentDomain.FriendlyName, e.ExceptionObject); }; var app = new Application(); while (true) { try { app.ProcessRequest(); } catch (Exception e) { // If we get here this mean that something is wrong with application // Let's break on line marked as #1 Console.WriteLine("Server swallowed an exception \"{0}\"", e.Message); Debugger.Break(); // Debugger breaks, but no exception dialog, and stack trace in method main } } }}
2 回答

小怪獸愛吃肉
TA貢獻1852條經(jīng)驗 獲得超1個贊
您可以附加 Visual Studio 調(diào)試器(或遠程調(diào)試器,如果它在單獨的機器上運行)。
步驟 1:在 Visual Studio IDE 中配置設置。
從菜單欄中,選擇調(diào)試 > Windows > 異常設置。
如果您選擇所有異常,當您附加到正在運行的進程時,這將導致調(diào)試器在每個異常(已處理和未處理)之前中斷。
第 2 步:附加到您的進程以在 Visual Studio(本地或遠程)中對其進行調(diào)試。
從菜單欄中,選擇“調(diào)試”>“附加到進程...”,然后按進程 ID 找到您的應用程序或 Web 應用程序池。
(注意:如果您是遠程調(diào)試,則將遠程調(diào)試器從您的 Visual Studio 安裝目錄復制到遠程計算機并以管理員身份運行,以便 Visual Studio 可以連接。通常它默認為端口 4020。)
- 2 回答
- 0 關注
- 208 瀏覽
添加回答
舉報
0/150
提交
取消