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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:47:20+00:00 2026-05-30T01:47:20+00:00

Are there situations where it is appropriate to use a try-finally block without a

  • 0

Are there situations where it is appropriate to use a try-finally block without a catch block?

  • 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-30T01:47:20+00:00Added an answer on May 30, 2026 at 1:47 am

    You would use it to ensure some actions occur after the try content or on an exception, but when you don’t wish to consume that exception.

    Just to be clear, this doesn’t hide exceptions. The finally block is run before the exception is propagated up the call stack.

    You would also inadvertently use it when you use the using keyword, because this compiles into a try-finally (not an exact conversion, but for argument’s sake it is close enough).

    try
    {
        TrySomeCodeThatMightException();
    }
    finally
    {
        CleanupEvenOnFailure();
    }
    

    Code running in finally is not guaranteed to run, however the case where it isn’t guaranteed is fairly edge – I can’t even remember it. All I remember is, if you are in that case, chances are very good that not running the finally isn’t your biggest problem 🙂 so basically don’t sweat it.

    Update from Tobias: finally will not run if the process is killed.

    Update from Paddy: Conditions when finally does not execute in a .net try..finally block

    The most prevalent example you may see is disposing of a database connection or external resource even if the code fails:

    using (var conn = new SqlConnection("")) // Ignore the fact we likely use ORM ;-)
    {
        // Do stuff.
    }
    

    Compiles into something like:

    SqlConnection conn;
    
    try
    {
        conn = new SqlConnection("");
        // Do stuff.
    }
    finally
    {
        if (conn != null)
            conn.Dispose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(See question below for more context): Are there any situations in which <machineKey validationKey=AutoGenerate,IsolateApps
In situations where two interfaces apply to an object, and there are two overloaded
I feel there is probably a well trodden design pattern to handle situations like
Situation: There are several entities in a simulated environment, which has an artificial notion
I have these two situations: String s = aa; s = s + aa;
I have this situation: There are a login page with a login form (form
I have the following situation: There is one custom view inside of the first
I will demonstrate the problem on a real example so the situation: there is
There is a situation where I need to have a suspend kind of behavior
There is the situation - i made some math modelling app on C#(WPF), showing

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.