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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:56:02+00:00 2026-05-15T00:56:02+00:00

what is a best practice in cases such as this one: try { //

  • 0

what is a best practice in cases such as this one:

try
{
   // do something
}
catch (SpecificException ex)
{
    Response.Redirect("~/InformUserAboutAn/InternalException/");
}

the warning i get is that ex is never used.

however all i need here is to inform the user, so i don’t have a need for it.

do i just do:

try
{
   // do something
}
catch
{
    Response.Redirect("~/InformUserAboutAn/InternalException/");
}

somehow i don’t like that, seems strange!!? any tips? best practices?

what would be the way to handle this.

thnx

  • 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-15T00:56:02+00:00Added an answer on May 15, 2026 at 12:56 am

    You just don’t declare the variable:

    try
    {
       // do something
    }
    catch (SpecificException)
    {
        Response.Redirect("~/InformUserAboutAn/InternalException/");
    }
    

    This is a moot point when catching System.Exception (in your original example, which is not exactly the same as an empty catch — an empty catch will also catch COM exceptions, for instance), but this is the correct construct to use.

    If you run your code through other analysis engines (Gendarme, for instance), you will also be warned that catching a plain Exception is poor practice because it can mask other exceptions besides what you really wanted to catch. That’s bitten me a few times while maintaining legacy code — we were catching and ignoring an Exception on a file delete (or something like that), but the main logic wasn’t working correctly. We should have been only catching an IOException, but we were catching and discarding the NullReferenceException that was causing the failure.

    That’s not to say you never should catch Exception; just rarely.

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

Sidebar

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.