I have read through a lot of tutorials and beginner questions on error handling in C. They all (well most) seem to go in this direction:
int main(){
if(condition){
fprintf(stderr, "Something went wrong");
exit(EXIT_FAILURE); // QUIT THE PROGRAM NOW, EXAMPLE: ERROR OPENING FILE
}
exit(0)
}
My question: is there any particular function in C that lets me catch an error, but only affect the status of the program (main) when it exits? Example of my idea:
int main(){
if(condition){
fprintf(stderr, "Something went wrong");
// Continue with code but change exit-status for the program to -1 (EXIT_FAILURE)
}
exit(IF ERROR CATCHED = -1)
}
Or do I have to create some custom function or use some pointer?