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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:23:09+00:00 2026-06-04T19:23:09+00:00

Are these two code examples the same? Catch and Catch (Exception e) have the

  • 0

Are these two code examples the same? Catch and Catch (Exception e) have the same output, and the result is also the same if I write Throw or Throw e.

Main:

try
{
    A();
    //B();
}
catch (Exception e)
{
    Console.WriteLine("{0} exception caught.", e);
}

Code 1:

static void A()
{
    try
    {
        int value = 1 / int.Parse("0");
    }
    catch (Exception e)
    {
        throw e;
    }
}

Code 2:

static void A()
{
    // Rethrow syntax.
    try
    {
        int value = 1 / int.Parse("0");
    }
    catch
    {
        throw;
    }
}
  • 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-04T19:23:11+00:00Added an answer on June 4, 2026 at 7:23 pm

    I think there are two questions here.


    What is the difference between throw and throw e;?

    I don’t think there is ever a good reason to write catch (Exception e) { throw e; }. This loses the original stacktrace. When you use throw; the original stacktrace is preserved. This is good because it means that the cause of the error is easier to find.


    What is the difference between catch and catch (Exception e)?

    Both of your examples are the same and equally useless – they just catch an exception and then rethrow it. One minor difference is that the first example will generate a compiler warning.

    The variable ‘e’ is declared but never used

    It makes more sense to ask this question if you had some other code in your catch block that actually does something useful. For example you might want to log the exception:

    try
    {
        int value = 1 / int.Parse("0");
    }
    catch (Exception e)
    {
        LogException(e);
        throw;
    }
    

    Now it’s necessary to use the first version so that you have a reference to the caught exception.

    If your catch block doesn’t actually use the exception then you would want to use the second version to avoid the compiler warning.

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

Sidebar

Related Questions

We have two code bases for testing and production. The only differences between these
I have a code base, in which for Matrix class, these two definitions are
Imagine two similar pieces of code: try { [...] } catch (myErr &err) {
I've been staring at the source code of these two download pages for awhile
Given the Java code below, what's the closest you could represent these two static
In my models.py, I user these code to extent two fields: User.add_to_class('bio', models.TextField(blank=True)) User.add_to_class('about',
I have two methods that do the same thing. The first one makes performance
I have two instances of NSScrollView both presenting a view on the same content.
Can someone please explain the difference between these two examples in the context of
I have a RelativeLayout with two children that are also both RelativeLayout s containing

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.