473,382 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

error handlling in C

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;
}

..............................................

}
Mar 28 '08 #1
2 1585
On Mar 28, 5:02 pm, broli <Brol...@gmail.comwrote:
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>
Mar 28 '08 #2
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
Mar 28 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
1
by: broli | last post by:
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;...
10
by: pereges | last post by:
How to to go about this ? Suppose a malloc inside a recursive function has failed and you want to set the error flag and return it to the calling function(the one which called the recursive...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.