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

  • SEARCH
  • Home
  • 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 4245956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:54:33+00:00 2026-05-21T03:54:33+00:00

I came across an interesting situation today: I have a small app with a

  • 0

I came across an interesting situation today: I have a small app with a settings file, which is well documented in the documentation, but if the file is not there, what would be better: throw a filenotfoundexception and give a very depressive message that the settings file is not available, or create a custom exception (already, the disadvantage is the work in doing this, even though it’ll take 10 minutes) called SettingsFileNotFoundException. This will give it away immediately, what the problem is.

The issue with the first approach (standard exception + message), is that in a team environment it will only work if it is a rigorously followed procedure.

Although I am not really interested in language specifics here, the language is C#.

Which would be better?

Thanks

  • 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-05-21T03:54:33+00:00Added an answer on May 21, 2026 at 3:54 am

    If you were catching SettingsFileNotFoundException on a different level (in a different, calling method) then it could make sense to create a custom exception because you might need to identify what exactly the error was. An over-simplified example is below:

    void startingMethod()
    {
        try
        {
            secondMethod();
            thirdMethod();
        }
        catch (SettingsFileNotFoundException sfnfe)
        {
            // Handle all SettingsFileNotFoundException issues here.
        }
        catch (Exception ex)
        {
            // Handle all other exceptions here.
        }
    }
    
    void secondMethod()
    {
        // TODO: secondMethod actions.
        var fileName = SomeLogicSpecificToSecondMethodHere();
    
        if (!File.Exists(fileName))
        {
            throw new SettingsFileNotFoundException("...");
        }
    }
    
    void thirdMethod()
    {
        // TODO: thirdMethod actions.
        var fileName = SomeOtherLogicSpecificToThirdMethodHere();
    
        if (!File.Exists(fileName))
        {
            throw new SettingsFileNotFoundException("...");
        }
    }
    

    In the above example, the program searches for multiple settings files and thus has multiple throw () statements that use the exception. And the nested exception catching allows for all of those exceptions to be handled in the same way without putting the same code in your two secondary methods. Here, having your custom exception as a different type allows that particular exception to be handled in a way different than the rest of your error handling.

    But assuming you aren’t doing this fancy of error handling, the first approach you described is better because it is generalized. Why would you create an exception that could be thrown only once? I assume you are caching your settings in variables so you do not need to read your file every five seconds, thereby making the possibility of using the new exception limited to one time during the initialization of the application.

    So in your case, unless you are very likely to expand your code to use more complex error handling in the future, you should probably just use a very specific message on a FileNotFoundException.

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

Sidebar

Related Questions

I came across an interesting question today where I have two methods that, at
I have came across very interesting problem which I think it's on Salesforce's end
Today while helping someone I came across an interesting issue which I couldn't understand
I came across an interesting situation. I have rebootet my WebRole through the Dashboard.
I just came across an interesting situation in JavaScript. I have a class with
I came across this interesting paragraph in the Boost thread documentation today: void wait(boost::unique_lock<boost::mutex>&
I came across an interesting problem today. I have a text email I'm sending
So I came across an interesting problem today. We have a WCF web service
I am working on a website and I came across an interesting situation. In
I came across an interesting problem today whilst implementing a feature into a dynamic

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.