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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:13:06+00:00 2026-05-17T23:13:06+00:00

try { some code } catch() { some code } finally { some code

  • 0
try
{
    some code
}
catch()
{
    some code
}
finally
{
    some code
}

try
{
    some code
}
catch()
{
    some code
}
finally
{
    some code
}

I know that if an exception is thrown in the first try block, then the first finally block will be executed. What about the second finally block?

Also, if you want to display the message to user when an exception arises, then where you should write that message, and how you should display it?

FYI, I was recently asked these questions in an interview, and was stumped.

  • 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-17T23:13:06+00:00Added an answer on May 17, 2026 at 11:13 pm

    Copy and paste this code into an editor. Then play around with it, uncommenting and re-commenting various lines. Then compile and run the code. Keep doing this until you’re pretty comfortable that you know everything about it. This is what I recommend you do when you find all such confusing questions, that are simply based on flow control. That is how you will learn programming flow control.

    try
    {
      Console.WriteLine("try1");
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    catch(ArgumentNullException e1)
    {
      Console.WriteLine("catch1");
      Console.WriteLine(e1.ToString());
      // throw;
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    catch(Exception e1a)
    {
      Console.WriteLine("catch1a");
      Console.WriteLine(e1a.ToString());
      // throw;
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    finally
    {
      Console.WriteLine("finally1");
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    
    try
    {
      Console.WriteLine("try2");
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    catch(ArgumentNullException e2)
    {
      Console.WriteLine("catch2");
      Console.WriteLine(e2.ToString());
      // throw;
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    catch(Exception e2a)
    {
      Console.WriteLine("catch2a");
      Console.WriteLine(e2a.ToString());
      // throw;
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    finally
    {
      Console.WriteLine("finally2");
      // throw new ArgumentNullException();
      // Console.WriteLine(((string)null).Length); // Will also throw exception
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a delegate function that can 'wrap' some while/try/catch code around
We have following code: try { // some code throwing MyException } catch (MyException
I have some code like this: try { doStuff(); } catch(SpecificException) { if(e.Message ==
I'm refactoring some code and there are tons of functions with no try catch
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
I have some code that looks like this: foreach(var obj in collection) { try
I have some code to update a database table that looks like try {
I'm trying to set up Eclipse so that it formats a try catch finally
So I came across some code this morning that looked like this: try {
I'm using simple-html-dom to try and pull some code from another site. Here's some

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.