Solved

Return to start function?

Posted on 2001-06-21
4
172 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now