How can I prevent the appearance of visual studio when my BackgroundWorker throws an error

When debugging my application, I always see the following messages:

An exception of type "xxxx.xxxxx" occurred in xxxxx.exe but was not processed in the user code.

The problem is that I have BackgroundWorkers that throw exceptions from their DoWork, which are then handled by checking the RunWorkerCompletedEventArgs.Error in the RunWorkerCompleted event - and it works fine at runtime.

Is there a way to prevent a visual studio from showing it as "raw"?

Isn't the right way to return DoWork errors back to the user interface?

I tried to make my exception an extended ApplicationException and disable the field next to ApplicationException in the exceptions dialog box, but it still displays.

+5
source share
1 answer

You need to catch and handle the exceptions inside the methods that the DoWork method calls. My recommendation would be to catch the exception and then use the ReportProgress event to report this back to the interface for smooth control / notification. You never want to β€œswallow” an exception, but this reporting will allow you to gracefully record the exception or notify the user in a less intrusive way.

, ReportProgress, UserState, .

+3

All Articles