.net - How do I catch an exception in a GUI thread? -


an exception thrown in user control based on picture box, causing show typical error image (red x). since gui thread caught , handled exception itself, cannot find out exception occurred , debug.

i'm wrapping whole onpaint code in try-catch, , able debug code, found quite tedious wondered if there way break debugger gui thread exception.

it works way default. ui thread exception handling method controlled application.setunhandledexceptionmode(). default unhandledexceptionmode.catchexception threadexception event raised and, default, creates threadexceptiondialog.

however, if debugger attached overrides mode. exception unhandled if there no active catch clause. debugger stop, allowing diagnose problem. writing own try/catch, prevent working.

do beware onpaint() can special, particularly picturebox. has try/catch clause, catching unhandled exception , painting red cross. bit unusual necessary because supports imagelocation property. lets display images potentially unreliable network source. best way trouble-shoot exceptions in case debug + exceptions, tick thrown checkbox. forces debugger stop on exception, if isn't unhandled.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -