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 8658597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:48:26+00:00 2026-06-12T15:48:26+00:00

According to this MSDN article , you should not catch general exceptions. I’m sure

  • 0

According to this MSDN article, you should not catch general exceptions. I’m sure there’s a stackoverflow question dealing with that, and I understand why it’s not a good practice but I just saw this example on another MSDN article today:

using System;
using System.IO;

class Test
{
    public static void Main()
    {
        try
        {
            using (StreamReader sr = new StreamReader("TestFile.txt"))
            {
                String line = sr.ReadToEnd();
                Console.WriteLine(line);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }
    }
}

Is there any justification to catching a general exception in that example or is it just that they were lazy to write an example catching all the specific exceptions?

  • 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-12T15:48:27+00:00Added an answer on June 12, 2026 at 3:48 pm

    In this case, this is an example and is a poor one at that, like many code examples on MSDN.

    This should be catching an IO Exception instead of the base class.

    The only place it would make sense to catch Exception is in a global exception handler for logging, provided you rethrow.

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

Sidebar

Related Questions

According to this article, http://msdn.microsoft.com/en-us/library/ms177197.aspx on MSDN, we should release the unmanaged resources in
According to this MSDN article about medium trust , under medium-trust: FileIOPermission is restricted.
I implement this function : GetSystemPowerStatusEx & GetSystemPowerStatusEx2 according to this article on MSDN
According to this msdn article one of the sources for InitialDirectory property used in
According to this MSDN article : The optional time zone indicator, Z, is used
According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
I have a generic question, and specific example. This should be easy according to
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
According to this article , it says: Use a delegate in the following circumstances:
I was reading custom serialization article on msdn: http://msdn.microsoft.com/en-us/library/ty01x675%28VS.80%29.aspx It mentions that there are

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.