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

Re: error handlling in C

Subject: Re: error handlling in C
From:
Date: Fri, 28 Mar 2008 08:20:35 -0700 PDT
Newsgroups: comp.lang.c

On Mar 28, 5:02 pm, broli <Brol...@xxxxxxxxx> wrote:
> Is it generally a good idea to use perror() function to handle all the
> error situations ?
>
> 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;
>      }
>
>     ..............................................
>
> }

If you afterwards decide to use another stream than strerr, then yes
it's bad.
Use fprintf(stream, %s%s\n", "File open error", strerror(errno))
strerror() is declared in <string.h>

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