Not everywhere I put try...catch in the project, but I saw some errors in the debug window. How to know the exact place of the exception so that I can correct?
HTML Code:Exception thrown: 'System.FormatException' in mscorlib.dll
Printable View
Not everywhere I put try...catch in the project, but I saw some errors in the debug window. How to know the exact place of the exception so that I can correct?
HTML Code:Exception thrown: 'System.FormatException' in mscorlib.dll
If your app is not crashing due to an unhandled exception but you're not catching it then that means that it's being caught within the system code, so it's not anything you need to worry about. Exceptions are allowed to be thrown. The system code has been written to account for that. You should be handling the UnhandledException event of the application in order to be able to log any exceptions in your code that you didn't anticipate but, other than that, leave it to the framework.
Not crash, but annoying. I will use try...catch one by one to duplicate the error and locate it.
By the way, why it generates an error?
Error is:Code:public void SetListBoxItemHeight()
{
using (Graphics graphics = CreateGraphics())
{
lstFoodCategories.ItemHeight = (int)Math.Round((double)(graphics.MeasureString("ABC", lstFoodCategories.Font).Height + 3F));
}
}
Quote:
Exception thrown: 'System.ArgumentException' in System.Drawing.dll
Parameter is not valid.
STOP! You're trying to solve a problem that doesn't exist. As I have already said, exceptions are allowed to be thrown. System code does a lot of things that you have no control over. Some of those things will cause exceptions to be thrown. That same system code is catching those exceptions and doing whatever is appropriate. Stop trying to fix something that you have no control over and no reason to care about.