P
pereges
Hi, I'm thinking of having a seperate module in my project that deals
with the exceptions and errors as they occur in a C program. Is this a
good idea ? I thought of doing this because it is getting really
repetitive to have the same thing in my code over and voer again eg.
if malloc fails then:
int *p;
p = malloc(sizeof(int) * 5);
if(p == NULL)
{
perror("malloc has failed");
exit(EXIT_FAILURE);
}
This situation may arise in many places in different contexts so what
I would like to do is identify such cases and have a seperate module
with a switch case that takes an error flag as an input and makes the
decision based on it. The error flags would represent the various
errors/exceptions like malloc failure, failure in opening file, scanf
failure, floating point exceptions , array out of bounds etc. I would
also like to print the name of the module where the exception occuerd
as well as the line number. Is there a function in C which provides
this facility ?
with the exceptions and errors as they occur in a C program. Is this a
good idea ? I thought of doing this because it is getting really
repetitive to have the same thing in my code over and voer again eg.
if malloc fails then:
int *p;
p = malloc(sizeof(int) * 5);
if(p == NULL)
{
perror("malloc has failed");
exit(EXIT_FAILURE);
}
This situation may arise in many places in different contexts so what
I would like to do is identify such cases and have a seperate module
with a switch case that takes an error flag as an input and makes the
decision based on it. The error flags would represent the various
errors/exceptions like malloc failure, failure in opening file, scanf
failure, floating point exceptions , array out of bounds etc. I would
also like to print the name of the module where the exception occuerd
as well as the line number. Is there a function in C which provides
this facility ?