gpt4 book ai didi

c# - 处理来自引用 dll 的未处理异常

转载 作者:太空狗 更新时间:2023-10-29 21:39:30 28 4
gpt4 key购买 nike

我已经创建了一个 c# dll 来处理应用程序中所有未处理的异常。

添加了

AppDomain appDomain = AppDomain.CurrentDomain;
appDomain.UnhandledException += new UnhandledExceptionEventHandler(MyErrorHandler);

我的 dll 项目中的代码,添加了对我的应用程序的引用。

在调试时,如果我的应用程序抛出未处理的异常,它会自动从 dll 中捕获,并且我成功登录到一个文件。

但是当我的应用程序被部署(或直接执行我的应用程序(双击 exe))时,dll 无法从应用程序中捕获未处理的异常。

最佳答案

参见 this在 MSDN 上

您可以尝试使用添加处理程序到应用程序的 threadException 以及 CurrentDomain Unhandled Exception 就像您在代码中编写的那样

Application.ThreadException += new ThreadExceptionEventHandler(Error_.MyExc);
Application.SetUnhandledExceptionMode(Error_.MyCatchExc);

// from your code
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyErrorHandler);

关于c# - 处理来自引用 dll 的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20947422/

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