Thread: goto from within try block

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    37

    goto from within try block

    Hi
    Just to make sure, if there is goto from within try block then we will not arrive to finally, correct?
    Thanks

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    'finally' - are you referring to structured exception handling or C++ handling?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is no finally block for exception handling in standard C++. If you really are asking with respect to some C++ compiler extension, then you should provide more details on the compiler that you have in mind. Oh, and a code example can help.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I think the more relevant question is: is there anything you can do to eliminate that goto? it's true that there are situations where a goto is the only/best option, but I think you should evaluate your code and determine if there's a better way in your case.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    37
    VS.
    Of course the code isn't mine, I need to maintain it while doing minimum changes.

  6. #6
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    But you still haven't given enough detail. Are you using a compiler with an extension that has a "finally" block? Can you post some code?

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Do you mean __finally from SEH exception handling?
    Give us a quick sample of what the code looks like.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by walla View Post
    VS.
    Of course the code isn't mine, I need to maintain it while doing minimum changes.
    I've made many mistakes over the years doing things the dumb way in an attempt to have "low impact" on the code I'm working on. It has lead to many very embarrassing, funny, and depressing outcomes. If you fear the code you won't have the courage to make the correct changes to it. Often there is an air of mystery or superstition surrounding such code. Look at it wrong and it might run over your mother in the parking lot.

    Let me tell you, from experience, any problems you imagine you might have from changing this code, pale in comparison to the trouble you're in for if you continue to pile hack upon hack on top of it. If this code is truly a Jenga tower ready to crumble at the slightest touch, do you really think sticking a goto into it will improve matters?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    37
    Just to say, I already gave up and changed this stupid goto
    Anyway currently there is no finally there.
    Let's say that is __finally
    Does goto from catch make __finally irrelevant?

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Quote Originally Posted by walla View Post
    Just to say, I already gave up and changed this stupid goto
    Anyway currently there is no finally there.
    Let's say that is __finally
    Does goto from catch make __finally irrelevant?
    You are mixing C++ exceptions with Structured Exception Handling (a compiler/platform specific extension used mainly on Windows). Have a read up on SEH to find out more - Introduction to Exception Handling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a goto
    By System_159 in forum C++ Programming
    Replies: 7
    Last Post: 12-10-2006, 04:04 AM
  2. goto
    By chrismiceli in forum C Programming
    Replies: 20
    Last Post: 08-26-2003, 07:19 AM
  3. goto or not goto
    By itld in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2002, 03:09 PM
  4. instead of goto
    By pode in forum C++ Programming
    Replies: 15
    Last Post: 02-20-2002, 05:29 AM
  5. Help with 'goto'
    By BubbleMan in forum Windows Programming
    Replies: 1
    Last Post: 09-22-2001, 10:54 AM