Solved

Return to start function?

Posted on 2001-06-21
4
174 Views
Last Modified: 2013-11-20
Hi experts,

I call function A(), A() calls B(),...., calls Z().
If something wrong in function Z(), program will be stoped by exit(0) in the function Z().
Now, I want it goes back to function A(), instead of stoped, if anything wrong in function Z().
I know we can do that by 'return' from z() to Y()....to A() but need hard work!

Any good suggestions?
0
Comment
Question by:learn
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
migel earned 60 total points
ID: 6214017
Hi!
use exception mechanism
that is:
A()
{
try
{
B();
}
catch(int)
{
// something wrong in the call chain
}
}

B()
{
Z();
}

Z()
{
if (error condition)
 throw 5; // generate exception;
}
0
 
LVL 3

Expert Comment

by:cypherljk
ID: 6214019
learn,
  I don't know what you mean by 'something goes wrong' but take a look at using 'try' and 'catch' blocks.  If an error or exception is caught it will be passed back up the calling stack.  the calling stack is a list of the functions that are currently executing. For example if A(), A() calls B(),...., calls Z() and exception 1 happens in z() if your catch block in in z catchs errors/exceptions of type 1 you could call a() from there OR you could have the catch in a(). You'll need to look up exceptions handling as there are many ways you can handle and pass exceptions and errors.

My 2 cents...
0
 

Author Comment

by:learn
ID: 6214640
Thanks a lot, that works great.

Thanks to all experts as well.....
0
 
LVL 3

Expert Comment

by:cypherljk
ID: 6216884
close the reference to this ? in the c++ section

my 2 cents...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 92
Include multiple hostnames in this command? 3 55
maxBlock challenge 30 130
My project did see openJDK that I installed. What could be the problem 7 143
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question