سؤال

I wrote a console application that uses Socket's *Async set of methods and it crashes time to time. It doesn't show me where it threw the exception like synchronized code, console just shuts down and I have no idea what have I done wrong.

Is there a way to detect exceptions when it comes to asynchronous operations like this without knowing where to put a try/catch block?

All I need is to know what part of the code makes my application crash.

Edit:

The usual thing with the unhandled exceptions is when you are debugging your code using Visual Studio, it pauses the execution and shows you the line of code that caused the exception (or at least the exception message). But in some situations (e.g. interacting with a low level API like IOCP) your program just crashes and debugging ends with no information about its cause.

What I need is a way to see that particular exception:
"What happened or where (in which method) it happened so my program crashed?"

So I don't ask "What have I done wrong?", I ask "How can I find out what have I done wrong?"

  • Can I make the execution break at the point where the exception is thrown?
  • Can I see the call stack after crash to identify the method that caused it?
  • Could you provide any advice to avoid these kind of situations?
هل كانت مفيدة؟

المحلول

Click Debug-menu -> Exceptions. Make sure Common Language Runtime Exceptions are thrown. Sometimes the IDE unchecks this option. I don't know why, but it's annoying.

نصائح أخرى

Enable System.Net logging to see whats happening underneath

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top