WinForms - 为什么我的异常没有被捕获?
在我的多线程服务器中,我使用以下代码(在运行表单本身或课程之前)
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ApplicationThreadException);
被调用的方法将异常写入列表,以便我可以轻松修复它。但是今天我来看到VS抛出了NullReference异常
,我不知道为什么它没有被捕获?
我可以通过调用来重现它:
stream = null;
stream.Flush();
该程序确实跳转到异常捕获范围,但它保留在 Flush 行上..奇怪。任何其他异常都处理得很好......也许是因为该方法尚未实现?
我确信我在“例外”列表中看到了“对象引用未设置为对象实例”,并且程序继续。为什么这个特殊的异常没有被捕获?
In my multithread server I am using following code (before running Form itself or course)
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ApplicationThreadException);
The called methods write exceptions to the list so I can fix it easily. But today I came and saw that VS has thrown NullReference exception
and I have no clue why it was not caught?
I can reproduce it by calling:
stream = null;
stream.Flush();
The program do jump to exception catching scope but it stays on the Flush line..strange. Any other exception is handled well..maybe its beacuse this method is not implemented yet?
Im sure I have seen "Object reference not set to an instance of object"
in my "exceptions" list and the program continued. Why isn't this particular exception caught?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了回答您的问题,我们需要有关引发的错误的更多信息。它源自您的代码吗?让我们看看堆栈跟踪。
另外,如果您在设置 ThreadException 之前调用 Application.Run(...),它不会捕获任何异常。
To answer your question, we need more information about the error that was thrown. Does it originate from your code? Let's see the stack trace.
Also, if you call Application.Run(...) before setting up the ThreadException, it won't catch any exceptions.
我们使用以下代码,发现它运行良好:-
谢谢,
Phil
http://exceptioneer.com
We use the following code and find it works well: -
Thanks,
Phil
http://exceptioneer.com