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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:51:18+00:00 2026-06-17T05:51:18+00:00

What if I had something like this: try { //work } catch (ArgumentNullException e)

  • 0

What if I had something like this:

try
{
   //work
}
catch (ArgumentNullException e)
{
   HandleNullException();
   Logger.log("ArgumentNullException " + e);
   DoSomething();
}
catch (SomeOtherException e)
{
   HandleSomeOtherException();
   Logger.log("SomeOtherException " + e);
   DoSomething();
}
catch (Exception e)
{
   HandleException();
   Logger.log("Exception " + e);
   DoSomething();
}

Now as we can see, I’m trying to handle exceptions for some different cases. BUT whenever an exception is raised, I’m always calling the method DoSomething() at the end. Is there a smarter way to call DoSomething() if there is an exception? If I added a finally block and called DoSomething() there, it would always be called, even when there is no exception. Any suggestions?

  • 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-17T05:51:19+00:00Added an answer on June 17, 2026 at 5:51 am

    If I added a finally block and called DoSomething() there, it would always be called, even when there is no exception.

    What you are looking for is known in the CLI standard (partition IIA, chapter 18) as a fault handler. Although .NET implements them, the C# language does not directly support them. However, they can be emulated:

    bool success = false;
    try
    {
        …
        success = true;
    }
    catch (…)
    {
        …
    }
    …
    finally
    {
        if (!success)
        {
            DoSomething();
        }
    }
    

    Note that there is no need to set the flag inside every catch handler, as some answers here suggest. Simply negate the test, and you only need to set the flag once, at the end of the try block.

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

Sidebar

Related Questions

Looking for a non-JS solution. Say I had something like this: <ul> <li> <form>
I have not had to do something like this in the past and am
I want to do something like this, but I haven't had much success so
Earlier this week, I had to do something which feels like a semantics violation.
If I had a CarsDataStore representing a table something like: Cars -------------- Ford |
So for development purposes, we had our folder structure for our website something like
This is something that I have had trouble with in the past and it's
I'm trying to do something like a bitwise enum in PHP according to this
In my WPF Window_Loaded event handler I have something like this: System.Threading.Tasks.Task.Factory.StartNew(() => {
I have a code like this: try { using (TransactionScope scope = new TransactionScope())

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.