1

In a Windows Forms application, the Application.Run method is wrapped with a try...catch block to make some kind of shielding. The exception is logged and a more user friendly message is shown.

The thing is that this works great when the debugger is attached (and the exceptions are not enabled on the "exception settings" windows for example.

But without a debugger (the situation that matters to me) we get this famous "unhandled exception" with the stack trace, etc:

enter image description here

So, the question is: How can I make my user friendly message box appear for the user?

I have tried to delete the .pdb and run release configuration, but nothing changed.

Thank you!

Community
  • 1
  • 1
Igor Kondrasovas
  • 1,479
  • 4
  • 19
  • 36
  • 1
    See [here](https://stackoverflow.com/questions/5762526/how-can-i-make-something-that-catches-all-unhandled-exceptions-in-a-winforms-a) for catching all unhandled exceptions. Ideally you should handle them before it gets to this point, of course :) – ProgrammingLlama Feb 01 '19 at 08:16
  • not all exceptions can be catched – vasily.sib Feb 01 '19 at 08:27

1 Answers1

1

You can handle the thrown exception try .. catch and in catch block show an messagebox with proper user friendly message.

try
{
 //your code here
}
catch(exception e)
{
  //log the exception
  MessageBox.Show($"Error Occurred with message {e.Message}");
}
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • 3
    The OPs issue isn't with **how** to display the message, the second sentence of the first para says "*The exception is logged and a more user friendly message is shown*", rather with the fact that sometimes their handler isn't being triggered and they're seeing the default handler, as shown in the screenshot – Rob Feb 01 '19 at 08:17