Re: error handlling in C



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
.



Relevant Pages

  • Re: error handlling in C
    ... int reader() ... If you afterwards decide to use another stream than strerr, ...
    (comp.lang.c)
  • error handlling in C
    ... Is it generally a good idea to use perror() function to handle all the ... int reader() ...
    (comp.lang.c)