Where do uncaught exceptions go with asynchronous I / O?


I am developing a console-based .NET application (using mono). I'm using asynchronous I/O (Begin/EndReceive).

I'm in the middle of a callback chain several layers deep, and if an exception is thrown, it is not being trapped anywhere (having it bubble out to the console is what I would expect, as there is currently no exception handling).

However, looking at the stack trace when I log it at the point where it occurs, the stack doesn't show it reaching back to the initial point-of-execution.

I've tried the AppDomain.UnhandledException trick, but that doesn't work in this situation.

System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: size
  at System.Net.Sockets.Socket.BeginReceive (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags socket_flags, System.AsyncCallback callback, System.Object state) [0x00000]
  at MyClass+State.BeginReceive () [0x00000]

I believe any error generated during an asynchronous call should be thrown upon calling the EndAction method (EndReceive in your case). At least, this is what I've experienced using the CLR (MSFT) implementation, and Mono should be doing the same thing, although it may perhaps be slightly buggy here (consider this as unlikely however). If you were in Visual Studio, I would recommend you turn on the option for catching all exceptions (i)n the Debug > Exceptions menu) - perhaps there is a similar option in whatever IDE you are using?