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

  • Home
  • SEARCH
  • 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 6828467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:23:11+00:00 2026-05-26T22:23:11+00:00

The using statement doesn’t capture exceptions. To catch exceptions you have two choices: 1)

  • 0

The using statement doesn’t capture exceptions. To catch exceptions you have two choices:

1) Unwrap the using and implement it manually:

void MyFunc()
{
    StreamReader myReader = null;

    try
    {
        myReader = new StreamReader(path);
        //use myReader
    }
    catch (Exception e)
    {
        //do something with exception
    }
    finally
    {
        if (myReader != null)
            myReader.Dispose();
    }
}

or 2) keep the using, and wrap it in another try catch block

void MyFunc()
{
    try
    {
        using (StreamReader myReader = new StreamReader(path))
        {
             //use myReader
        }
    }
    catch (Exception e)
    {
        //do something with exception
    }
}

To me the second one looks neater, especially when you having multiple using statements, because it describes the flow better, and removes the explicit declarations, null checks and Dispose() calls.

However, it feels wrong due to the extra try catch overhead which effectively redundant.

What’s the standard practice?

  • 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-26T22:23:12+00:00Added an answer on May 26, 2026 at 10:23 pm

    The overhead of exception handling constructions is just metadata. There is no runtime performance overhead if no exception gets thrown. Unlike some other runtimes entering/leaving an exception handling clause is free in .net. When an exception is thrown the runtime uses the metadata and the current instruction-pointer to figure out which handling clauses to execute.

    I favor the second one. Releasing resources and handling exceptions are separate concepts, so it’s only natural for them to be separate in code.

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

Sidebar

Related Questions

I have used the using statement in both C# and VB. I agree with
I am just looking at the using statement, I have always known what it
The using(...) statement is syntactic sugar for try{} finally {}. But if I then
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
C# has the using statement, specifically for IDisposable objects. Presumably, any object specified in
Is it safe to use the using statement on a (potentially) null object? Consider
I understand the concept and reasons behind using the using statement, and I use
Is there any easy way to add a using statement to every class I
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
Similar to my question about returning from inside a using statement (whose answer was

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.