在我的 asp.net 应用程序中,如果应用程序抛出异常,它会被捕获并改为提供 500 页。我想在抛出位置中断调试器。目前我正在使用以下代码片段:
void ExceptionHandler(Exception ex) {
if (Debugger.IsAttached)
{
Debugger.Break();
}}
然而,这段代码在ExceptionHandler,而不是在抛出位置中断。我怎样才能在投掷位置打破?
我不想更改异常设置,因为我想中断达到的异常ExceptionHandler,而不是系统从中恢复的异常。
为了更好地说明我的问题:
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
}
}
}
}
小怪兽爱吃肉
相关分类