应用程序关闭和 Windows 错误报告
我们正在尝试更新我们的应用程序,以便提交 Vista 认证。 部分要求是仅处理已知的异常,并让 Windows 错误报告处理所有未处理的异常。
我们的应用程序中有一个全局异常处理程序(订阅了 Application.ThreadException
事件),在其中,我们对已知异常执行某些处理,但如果异常未知,我们希望将其抛出要终止的应用程序和要处理的 WER。
如果我们重新抛出然后重新创建调用堆栈,我们就找不到执行此操作并维护调用堆栈的方法。
我们考虑过通过 Environment.FailFast()
终止,但我们不认为这会提供我们需要的异常信息。
我们是否遗漏了一些明显的东西?
We're attempting to update our application in order to submit it for Vista certification. Part of the requirements are to handle only known exceptions and have Windows Error Reporting deal with all unhandled exceptions.
We have a global exception handler in our application (subscribed to the Application.ThreadException
event) and in there, we perform certain processing for known exceptions, but if an exception is unknown we wish to throw it out for the app to terminate and WER to handle.
We cannot see a way of doing this and maintaining the call stack if we re-throw then the call stack is recreated.
We've looked at terminating via Environment.FailFast()
but we don't believe that that gives the exception information we'd require.
Are we missing something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不直接抛出一个新的异常并将 InnerException 属性设置为未处理的异常呢? 默认的 StackTrace 属性会将两个跟踪连接在一起。
请记住,如果您从从 WinQual 检索到的内存转储进行调试,那么无论如何它都将是一个被捕获的本机异常。 几乎总是可以返回本机堆栈并检索托管异常,如果有可用的符号,通常很容易找出问题所在。 无论如何,在这种情况下,托管异常的堆栈跟踪将是多余的。
Why not just throw a new exception and set the InnerException property to be the unhandled one? The default StackTrace property will concatenate both traces together.
Bear in mind that if you're debugging from a memory dump that you've retrieved from WinQual then it'll be a native exception that's trapped anyway. It's almost always possible to walk back up the native stack and retrieve the managed exception and if you have symbols available it's usually easy to find out what went wrong. The stack trace of the managed exception will be redundant in this situation anyway.
是的,但是我们位于 Application.ThreadException 全局处理程序中,而不是 catch 块中,因此我们不能只调用 throw,我们必须抛出 e.Exception。
Yes but we're within the Application.ThreadException global handler, not a catch block so we can't just call throw, we'd have to throw e.Exception.
是的,正如 Marc 所说,只需使用 THROW,原始异常将被重新抛出,并保留堆栈跟踪信息。
THROW E 将重新启动整个异常堆栈,并丢失原始堆栈信息。 通常这不是您想要的。
或者,您可以抛出一个新的异常并将原始异常添加为内部异常。 然后你的新异常可以添加额外的信息。
Yea, as Marc states, just use THROW and the original exception will be re-thrown with the stack trace information preserved.
A THROW E will start the whole exception stack over again with the original stack information lost. Typically this is not what you want.
Alternative you can throw a new exception and add the original exception as an inner exception. Then your new exception could add additional bits of information.