Link to home
Start Free TrialLog in
Avatar of eccles
eccles

asked on

Not returning from a function

This may be a silly question. I want to call a function and, depending on the result, NOT return to the originating sub routine (if an error occurs for example). Can this be done? Have I missed something really obvious?

Thank you for any help you can give.

Peter
ASKER CERTIFIED SOLUTION
Avatar of mukvij
mukvij

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eccles
eccles

ASKER

I understand. So control will ultimately return to the originating function/sub unless I terminate the application. Is this final? Is there no way around this? I really don’t want to have branch off indefinitely in the application.

Pete


Don't do this. You're going to wind up with an app that generates GPF's. You have to return from a function in order to clean up the internal stack. If you don't, your app will corrupt memory and eventually choke. Are you trying to write *buggy code*?

Allow the function to return and return a flag value so you know if you should trigger your error exit. If your code is not structured to handle this, then REWRITE it. It may be a PITA for *YOU* to rewrite, but it will be an even *BIGGER* PITA for the users when your app goes belly up and dumps their data.

If you don't *care* about the users then turn in your "I'm a programmer" card and go into a different trade. :-(

M

I totally agree with mark. As I said earlier branching off indefinitely is not a good programming practise as it does not confirm to standards of structured programming. I also agree with the idea given by Mark to have function return some flag based on which you can decide what to de next.
Yeah, it's code like that which has given BASIC it's bad rep among programming languages.

If you were to write something like that in *MY* shop you'ld be looking for a new job.

M

Avatar of eccles

ASKER

Thank you mukvij for your comments and help. Mark, please get off your high horse! It was a QUESTION for gods sake!!! For your information I have already written the code with each function returning a status code. I asked the question to see if there was a better way of doing it. I do not pretend to know everything about programming (unlike your self).

Once again mukvij thank you for your help.

Pete