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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:17:19+00:00 2026-05-31T20:17:19+00:00

I wrote a simple program to test a theory that finally block will always

  • 0

I wrote a simple program to test a theory that “finally” block will always execute no matter what.
But, what i’m seeing from the below pgm is that control never seems to enter the outer finaly block.

I tried doing F5 and also Ctrl-F5 in Visual studio and it’s the same result.

Can someone explain why I’m seeing this behavior?

Output on the console window is :

inner catch

inner finally

outer catch

unhandled exeption:

..and then the app crashes

public class Program
{
    static void Main()
    {
        try
        {
            try
            {
                string s = null;
                s.ToString();
            }
            catch
            {
                Console.WriteLine("inner catch");
                throw;
            }
            finally
            {
                Console.WriteLine("inner finally");
            }

            return;
        }
        catch
        {
            Console.WriteLine("outer catch");
            throw;
        }
        finally
        {
            Console.WriteLine("outer finally");
        }
    }
}
  • 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-31T20:17:20+00:00Added an answer on May 31, 2026 at 8:17 pm

    The "outer finally" is run, just after the exception is handled.

    Here is the output from running this code outside of the debugger:

    inner catch
    inner finally
    outer catch
    
    Unhandled Exception: System.NullReferenceException: Object reference not set to
    an instance of an object.
       at SOConsole.Program.Main() in c:\Users\DaveShaw\Documents\Visual Studio 11\Pro
    jects\SO\SOConsole\Program.cs:line 35
    outer finally
    Press any key to continue . . .
    

    When the exception occurred the following was displayed:
    Exception

    After I clicked "Cancel", the application resumed and displayed the "outer finally".

    If for some reason you close down your application before it has chance to enter the "outer finally" then you will never see you message. If an application’s process is "terminated" then the finally’s are skipped in case they contain code that prevents the application from closing. Otherwise it may be impossible to terminate that process.

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

Sidebar

Related Questions

I wrote a simple program that using Class::ArrayObjects but It did not work as
I wrote a simple test program in c++ but why does this crash on:
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I need to write a simple program that records all the input from parallel
I'm learning to work with lucene. I wrote a simple program to test lucene
I'm learning java and I have made simple program that simply reads value from
I wrote a simple hello world program to test the JDK installation. I can
I wrote a simple C++ program to illustrate my problem: extern C{ int test(int,
I wrote a simple test program, where I was doing Complex to Complex FT's
The problem is this: I wrote a simple program that uses FFMPEG. compile as

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.