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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:55:52+00:00 2026-06-11T03:55:52+00:00

Possible Duplicate: How slow are .NET exceptions? Is there an overhead for throwing an

  • 0

Possible Duplicate:
How slow are .NET exceptions?

Is there an overhead for throwing an exception and catching it right away?
Is there a difference between this

void DoSomething(object basic)
{
    try
    {
       if (basic == null)
         throw new NullReferenceException("Any message");
       else
       {
         //...
       }
    }
    catch (Exception error)
    {
       _logger.WriteLog(error);
    }
}

and this (here we don’t throw exception):

void DoSomething(object basic)
{
    try
    {
        if (basic == null)
        {
            _logger.WriteLog(new NullReferenceException("Any message");
            return;
        }
        else
        {
         ...
        }
    }
    catch (Exception error)
    {
        _logger.WriteLog(error);
    }
}

Will the second fragment be faster, or not?

Also I want to know why one solution is faster than another.

  • 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-11T03:55:53+00:00Added an answer on June 11, 2026 at 3:55 am

    Exceptions are slower than all other program flow but not to the extent they should be avoided for performance reasons. However, they are not meant to be used for program flow. In your situation, you have a very valid alternative that is better than using exceptions. When you can predict a situation and handle it appropriately without exceptions, always do that. Also, don’t use exceptions in normal program flow as a convenience.

    Use exceptions when you have an unanticipated exceptional situation you can’t handle directly.

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

Sidebar

Related Questions

Possible Duplicate: Slow Android emulator Is there any fast and more efficient android emulator
Possible Duplicate: jquery mouseleave issue when moving too slow There seems to be a
Possible Duplicate: Do comments slow down an interpreted language? Will there be noticeable performance
Possible Duplicate: .NET - Check if directory is accessible without exception handling Im making
Possible Duplicate: Slow Android emulator I am using Eclipse to load the Android project
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: Are .NET 4.0 Runtime slower than .NET 2.0 Runtime? Hello All, We
Possible Duplicate: How to select an element by class inside “this” in Jquery I'm

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.