Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:00:52+00:00 2026-06-10T03:00:52+00:00

I have a line: string[] cPathDirectories = Directory.GetDirectories(Properties.Settings.Default.customerFolderDirectory); that will throw the error Path

  • 0

I have a line:
string[] cPathDirectories = Directory.GetDirectories(Properties.Settings.Default.customerFolderDirectory);

that will throw the error “Path is not of legal form” if the user didn’t specify a search path (this setting is saved as String.Empty at this point). I would like throw this error to say, “Hey you idiot, go into the application settings and specify a valid path” instead. Is there a way to do this instead of:

...catch (SystemException ex)
{
   if(ex.Message == "Path is not of legal form.")
      {
          MessageBox.Show("Hey you idiot, go into the application settings and specify a valid path","Error");
      }
      else
      {
          MessageBox.Show(ex.Message,"Error");
      }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:00:53+00:00Added an answer on June 10, 2026 at 3:00 am

    No, you need to check what the type of the exception is and catch that explicitly. Testing for strings in exception messages is a bad idea because they might change from one version of the framework to another. I’m pretty sure Microsoft doesn’t guarantee that a message will never change.

    In this case, looking at the docs you might be getting either a ArgumentNullException or ArgumentException, so you need to test for that in your try/catch block:

    try {
        DoSomething();
    }
    catch (ArgumentNullException) {
        // Insult the user
    }
    catch (ArgumentException) {
        // Insult the user more
    }
    catch (Exception) {
        // Something else
    }
    

    Which exception you need here, I have no idea. You need to determine that and structure your SEH block accordingly. But always try to catch exceptions, not their properties.

    Note the last catch is highly recommended; it ensures that if something else happens you won’t get an unhandled exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 1.2GB file that contains a one line string. What I need
I have multiple line string that I'd like to replace, but don't understand why
I have a string containing the following multi-line string value that I read from
Im developing a simple application that have a line like this: string[] values =
I have a regular expression that parses a line# string from a log. That
I have a multi-line string that I want to do an operation on each
I have a string that looks like this. It's obviously a multi-line string and
I have 3 strings that have the following format(each on its own line): String
I have a string line like the following : A:B:C:D:E:F:G:H:I:J:K:L:M It means delimiter (
i have the next code: std::string line; std::ifstream myfile (text.txt); if (myfile.is_open()) { while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.