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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:57:57+00:00 2026-05-10T13:57:57+00:00

Whilst analysing some legacy code with FXCop, it occurred to me is it really

  • 0

Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception. Thoughts on a postcard please.

  • 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. 2026-05-10T13:57:57+00:00Added an answer on May 10, 2026 at 1:57 pm

    Obviously this is one of those questions where the only real answer is ‘it depends.’

    The main thing it depends on is where your are catching the exception. In general libraries should be more conservative with catching exceptions whereas at the top level of your program (e.g. in your main method or in the top of the action method in a controller, etc) you can be more liberal with what you catch.

    The reason for this is that e.g. you don’t want to catch all exceptions in a library because you may mask problems that have nothing to do with your library, like ‘OutOfMemoryException’ which you really would prefer bubbles up so that the user can be notified, etc. On the other hand, if you are talking about catching exceptions inside your main() method which catches the exception, displays it and then exits… well, it’s probably safe to catch just about any exception here.

    The most important rule about catching all exceptions is that you should never just swallow all exceptions silently… e.g. something like this in Java:

    try {      something();  } catch (Exception ex) {} 

    or this in Python:

    try:     something() except:     pass 

    Because these can be some of the hardest issues to track down.

    A good rule of thumb is that you should only catch exceptions that you can properly deal with yourself. If you cannot handle the exception completely then you should let it bubble up to someone who can.

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

Sidebar

Related Questions

Whilst refactoring some legacy C++ code I found that I could potentially remove some
Whilst refactoring some old code I realised that a particular header file was full
Whilst refactoring some code I came across some getter methods that returns a std::string.
Whilst trawling through some old code I came across something similar to the following:
Whilst poking around some code using a .NET Reflector for an app I don't
Whilst programming in Objective-C I've occasionally had methods throw an exception that I wasn't
Whilst reviewing some Qt C++ code I came across this: class Foo { Q_OBJECT
Whilst investigating an internationalisation issue in some Java code whereby on a Japanese Windows
Whilst investigating a memory leak I discovered that it was caused by calling NewRow()
Whilst messing around with some x86 asm, I got to wondering about cases where

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.