Re: error handlling in C
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Mar 2008 18:57:01 +0000
broli wrote, On 28/03/08 15:02:
Is it generally a good idea to use perror() function to handle all the
error situations ?
As ever, it depends.
For eg in one of my modules I have used it extensively.
int reader()
{
FILE *zeus_file;
....................
.....................
zeus_file = fopen("sphere.zeus", "r");
if(zeus_file == NULL)
{
perror("File open error");
return -1;
}
..............................................
}
Now consider changing it to take the file name as a parameter and then doing something like:
if (reader("main-config-file"));
else if (reader("alternate-config-file");
else ...
Sometimes you can handle the error without bothering the users, other times you want to log it to a file, sometimes send it to stderr. It all depends.
--
Flash Gordon
.
- References:
- error handlling in C
- From: broli
- error handlling in C
- Prev by Date: Re: printf and cout
- Next by Date: Re: The problems in comp.lang.c
- Previous by thread: Re: error handlling in C
- Next by thread: Scatologic ,incestuous family
- Index(es):
Relevant Pages
|