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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:50:40+00:00 2026-05-27T03:50:40+00:00

In C# (when using a try / finally) how can I jump to the

  • 0

In C# (when using a try / finally) how can I jump to the finally section without calling return.

For example:

public bool SomeMethod()
{
    try
    {
        ...
        if (...)
        {
            ---> Jump to finally
        }
        else
        {
            ...
        }

        ...

        if (...)
        {
            ---> Jump to finally
        }
        else
        {
            ...
        }
        ...
        return true;
    }
    finally
    {
        ...

        if (...)
            return true;
        else
            return false;
    }

}

How can I force a jump to the finally section (without using return)?

Edit:

What I’m trying to do is:

public bool SomeMethod(ref string Error)
{
    try
    {
        bool result = false;

        if (...)
            ---> Exit to Finally
        else
            ...

        ...

        if (...)
            ---> Exit to Finally
        else
            ...

        ...

        --> more of the above kind of IFs

        return true;
    }
    finally
    {
        ...

        if (!result)
        {
                LogAMessage("");
                ...
                Error = "...";
                ...
        }
        return result;
    }

}
  • 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-27T03:50:41+00:00Added an answer on May 27, 2026 at 3:50 am

    You could use a label and goto.

    However, this seems to suggest that your function is probably not structured well.

    In this case, you seem to be using finally as a function – why not extract that logic into a function of its own?

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

Sidebar

Related Questions

Can someone enlighten me on handling the database connection (and errors) using try finally
Is there a way to dispose method variables without using try-finally block in C#
The using(...) statement is syntactic sugar for try{} finally {}. But if I then
Since the C# using statement is just a syntactic sugar for try/finally{dispose}, why does
I understand how try-catch works and how try-finally works, but I find myself using
Out of habit I've been using try/catch blocks in my application code for all
What kind of performance implications are there to consider when using try-catch statements in
I am writing a stored procedure where i m using try catch block. Now
Recently, I made a post about the developers I'm working with not using try
I try using evt.parent.attr(id) inside jsddm_close, but it doesn't work. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script

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.