gpt4 book ai didi

c# - 处理错误 "WebDev.WebServer.Exe has stopped working"

转载 作者:可可西里 更新时间:2023-11-01 09:15:47 27 4
gpt4 key购买 nike

有没有一种方法可以处理 ASP.NET 中的“WebDev.WebServer.Exe 已停止工作”错误并保持页面运行甚至只是 WebServer 运行?或者这是一项不可能完成的任务,本质上就像是在问如何在人死后挽救他们的生命?

我在 try/catch block 中有导致错误的代码,但这没有什么区别。我也试过注册一个新的 UnhandledExceptionEventHandler,但这也没有用。我的代码在下面,以防我做错了什么。

另外需要说明的是,我并不是在寻求有关如何防止错误的帮助;我想知道错误是否以及何时发生,如果我能做些什么来处理它。

更新 1:TestOcx 是一个 VB6 OCX,它将字符串的引用传递给用 Clarion 编写的 DLL。 .

更新 2:根据@JDennis 的回答,我应该澄清 catch(Exception ex) block 也没有被输入。如果我从 try\catch block 中删除对 OCX 的调用,它仍然不会到达 UnhandledException 方法。基本上有两个区域永远不会执行。

更新 3:来自@AndrewLewis,我还尝试添加一个常规的 catch block 来捕获任何不符合 CLS 的异常,但这也不起作用。但是,我后来发现自从 .NET 2.0 以来,所有非 CLS 异常都包含在 RuntimeWrappedException 中,因此 catch (Exception) 也会捕获非 CLS 兼容的异常。查看this other question here了解更多信息。

public bool TestMethod()
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

string input = "test";
string result = "";
try
{
TestOcx myCom = new TestOcx();
result = myCom.PassString(ref input); // <== MAJOR ERROR!
// do stuff with result...
return true;
}
catch (Exception ex)
{
log.Add("Exception: " + ex.Message); // THIS NEVER GETS CALLED
return false;
}
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// THIS NEVER GETS CALLED
try
{
Exception ex = (Exception)e.ExceptionObject;
log.Add("Exception: " + ex.Message);
}
catch (Exception exc)
{
log.Add("Fatal Non-UI Error: " + exc.Message);
}
}

最佳答案

您应该 try catch 不符合 CLS 的异常,以确保没有抛出任何东西(请记住,您不想在生产中这样做,始终要具体!):

try
{
TestOcx myCom = new TestOcx();
result = myCom.PassString(ref input); // <== MAJOR ERROR!
// do stuff with result...
return true;
}

catch (Exception ex)
{
log.Add("Exception: " + ex.Message); // THIS NEVER GETS CALLED
return false;
}
catch
{
//do something here
}

关于c# - 处理错误 "WebDev.WebServer.Exe has stopped working",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12611201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com