Home > Software design >  Exception unhandled popup
Exception unhandled popup

Time:12-17

I recently began to create my own desktop application on visual studio via the .net framework and winforms. I'm starting to understand more and more of the process, but this one thing is bugging me. When an exception occurs, I get this popup with exception unhandled, but this exception is showed at the Application.Run(new Form1()); in the standard program.cs. I know this is an exception in the Form1.cs file, but how can i found out at which line this exception occurs? I don't really understand the quickwatch window when I press "view details". It is probably a stupid thing i just don't see, cause i can't find anything online.

Thank you in advance!

example of an exception

CodePudding user response:

That's unfortunately how it works, because the main loop of the application is inside that Run() method. That main loop contains some exception handling code, but throws the ones that are interesting for you further up. The debugger will by default only kick in on that second place where the exception is rethrown, which doesn't show you much information.

You have the following possibilities:

  • Inspect the stack trace: In the popup, click the "View Details" link. There you have one field that shows the stack trace (that is the list of functions that have called into the place where the error happened). The top of it is the most recently called function and therefore the one that caused the problem.
  • Configure the debugger to break when the exception is thrown, not only when it is unhandled. Open the Exception settings window (Under Debugger->Windows) and add a checkbox next to "Common language exceptions". This now might show some exceptions that you handle properly, but normally, there shouldn't be many of those in normal program flow. When you right-click the setting, you can change it back to normal, when you expand it, you can configure the behavior for each exception type individually.

CodePudding user response:

As we can see from your screenshot, the decimal value is too large or too small. https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/decimal-data-type

If we want to found out at which line this exception occurs, we can set a breakpoint and start the debugger. This page can help you use the debugger. https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour?view=vs-2022

  • Related