comp.lang.c
[Top] [All Lists]

Re: error handlling in C

Subject: Re: error handlling in C
From: Flash Gordon
Date: Fri, 28 Mar 2008 18:57:01 +0000
Newsgroups: comp.lang.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

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy