可以异步I / O抛出一个不可捕获的异常? [英] Can an async I/O throw an uncatchable exception?

查看:746
本文介绍了可以异步I / O抛出一个不可捕获的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程的.NET应用程序,使用异步I / O和AsyncCallbacks处理I / O完成。少数情况下,应用程序将失败,并出现异常,如:

I have a multi threaded .NET app that uses async I/O and AsyncCallbacks to handle the I/O completions. Rarely, the app will fail with an exception like:

Arithmetic operation resulted in an overflow.
   at MyApp.ReadComplete(IAsyncResult ar) in c:\MyApp.cs:line 123
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

123线在MyApp.cs是的AsyncCallback的第一个可执行行,这是一个try / catch(异常前)内,但是,没有被执行的渔获物。

Line 123 in MyApp.cs is the first executable line of the AsyncCallback and it is inside of a try/catch (Exception ex) but, the catch is NOT being executed.

是.NET Framework骗我,发生异常?难道除了实际发生在异步阴曹地府,我无法抓住它?为什么我不能捕获此异常?

Is the .NET Framework lying to me about where the exception occurred? Did the exception actually occur out in the async netherworld where I can't catch it? Why can't I catch this exception?

推荐答案

实际的答案是肯定的,.NET框架是错发生异常,但是,不能因为在异步阴曹地府发生过异常。唯一的例外实际发生的回调方法,该行后,许多线表示的堆栈跟踪。除实际发生在那里的路线是不是一个try / catch块左右,未处理的异常是预期内的。

The actual answer is yes, the .NET Framework was wrong about where the exception occurred but, not because the exception occurred off in the async netherworld. The exception actually occurred in the callback method, many lines after the line indicated in the stack trace. The line where the exception actually occurred was NOT inside of a try/catch block so, the unhandled exception was expected.

我报了不正确的堆栈跟踪到微软,但不知道,如果它被认为是一个错误。

I reported the incorrect stack trace to Microsoft but have no idea if it is considered a bug.

我认为这是肯定地说,如果你的堆栈跟踪指向一个异步回调方法的第一个可执行行,你应该怀疑它可能是错的。

I think that it's safe to say that if your stack trace points to the first executable line of an async callback method, you should suspect that it could be wrong.

这篇关于可以异步I / O抛出一个不可捕获的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆