Results 1 to 6 of 6

Thread: [RESOLVED] where is the origin of Exception in VS2022?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    609

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,687

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    609

    Re: where is the origin of Exception in VS2022?

    Quote Originally Posted by jmcilhinney View Post
    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    609

    Re: where is the origin of Exception in VS2022?

    Quote Originally Posted by DaveDavis View Post
    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...

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,687

    Re: where is the origin of Exception in VS2022?

    Quote Originally Posted by DaveDavis View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,687

    Re: where is the origin of Exception in VS2022?

    Quote Originally Posted by DaveDavis View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Click Here to Expand Forum to Full Width