-
Mar 2nd, 2023, 08:14 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] where is the origin of Exception in VS2022?
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
-
Mar 2nd, 2023, 08:41 PM
#2
Re: where is the origin of Exception in VS2022?
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.
-
Mar 2nd, 2023, 08:49 PM
#3
Thread Starter
Fanatic Member
Re: where is the origin of Exception in VS2022?
Originally Posted by jmcilhinney
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?
Code:
public void SetListBoxItemHeight()
{
using (Graphics graphics = CreateGraphics())
{
lstFoodCategories.ItemHeight = (int)Math.Round((double)(graphics.MeasureString("ABC", lstFoodCategories.Font).Height + 3F));
}
}
Error is:
Exception thrown: 'System.ArgumentException' in System.Drawing.dll
Parameter is not valid.
-
Mar 2nd, 2023, 09:08 PM
#4
Thread Starter
Fanatic Member
Re: where is the origin of Exception in VS2022?
Originally Posted by DaveDavis
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?
Code:
public void SetListBoxItemHeight()
{
using (Graphics graphics = CreateGraphics())
{
lstFoodCategories.ItemHeight = (int)Math.Round((double)(graphics.MeasureString("ABC", lstFoodCategories.Font).Height + 3F));
}
}
Error is:
OK, the error is due to somehow lstFoodCategories.Font is null...
-
Mar 2nd, 2023, 09:18 PM
#5
Re: where is the origin of Exception in VS2022?
Originally Posted by DaveDavis
Not crash, but annoying. I will use try...catch one by one to duplicate the error and locate it.
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.
-
Mar 2nd, 2023, 09:20 PM
#6
Re: where is the origin of Exception in VS2022?
Originally Posted by DaveDavis
By the way, why it generates an error?
Code:
public void SetListBoxItemHeight()
{
using (Graphics graphics = CreateGraphics())
{
lstFoodCategories.ItemHeight = (int)Math.Round((double)(graphics.MeasureString("ABC", lstFoodCategories.Font).Height + 3F));
}
}
Given that that is C# code and this is a VB.NET forum, it's not really a question to answer here. If you have a C# question, please post it in the C# forum in a thread on that subject, not piggybacking off another question.
Last edited by jmcilhinney; Mar 2nd, 2023 at 09:29 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|