hello everybody

void func1(){
// do something

//exit the function if some error occurs (like segmentation fault) but continue running the rest of the program
}

void func2(){

//do something

//exit the function if some error occurs (like segmentation fault) but continue running the rest of the program

}

int main(){
func1();
func1();
}

Ok for the above program, if any error (such as segmentation fault) occurs in func1, i want the function to end but continue running the rest of the program (i.e func2). I have used exit() and return 0, but not working. HELP!!!

Return from the function with a return statement and the program will continue to run from that point on. But if the program depends on results from the function that errored, you'll have problems later on.

Return from the function with a return statement and the program will continue to run from that point on

This is quite hard to do considering that "some error" can be a segfault. The OP goal is achieved via setjmp in the caller and longjmp from the signal handler.

Oh, I didn't see that a seg fault was one of the potential errors. My bad.

Return from the function with a return statement and the program will continue to run from that point on. But if the program depends on results from the function that errored, you'll have problems later on.

Thanks a lot for your reply... but truely speaking i am a newbie in C, is it return 0 or return 1? the function is independent, its a test program, it executes and ends there, nothing is return, function starts with a void....

function starts with a void....

Then you would use an empty return statement:

void foo()
{
    ...

    if (some error)
    {
        return;
    }

    ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.