Skip to contentSkip to conversation

error programming

DISCUSSION r_zaca 4 participants 4 messages Jan 13, 2005 – Jan 14, 2005

lore
Share & tools
lore

r_zaca

author
#0 lore raw

Hi all,

Can anybody sugest me a good documentation about how all the functions
related to "error treatment" on linux work?
I know there is a "variable" called errno that is set when a error about
something happens and that I can read this value through perror, (at least I think it works that way) but how it really works I have no idea. So any tip on this subject will be nice.
Thanks again.

#1 lore raw
Quoted 9 lines · r_zaca

Hi all,

Can anybody sugest me a good documentation about how all the functions
related to "error treatment" on linux work?
I know there is a "variable" called errno that is set when a error about
something happens and that I can read this value through perror, (at least I think it works that way) but how it really works I have no idea. So any tip on this subject will be nice.
Thanks again.

take a look to "Advanced Linux Programming".
It speaks about errors too.
FG

_________________________________________________
Francesco Gadaleta - Italian GNU/Linux User
web site: www.gadaleta.org
email : [email protected]
ICQ : 286063291
Fingerprint: 3CB8 C721 FE99 BC98 38DC F463 BFDC E4EC CE3B 7327 (1024/DSA) [with image]
Linux Registered User #327326
__________________________________________________
Pls do not send me Word or Powerpoint files
RMS'll explain you why, here:
http://www.gadaleta.org/articles/ita/allegati_word.html

#2 lore raw
In reply to r_zaca

Hello r_zaca,

Quoted 8 lines · On Thu, 13 Jan 2005 17:21:22 -0200 r_zaca <[email protected]> wrote:

Hi all,

Can anybody sugest me a good documentation about how all the functions
related to "error treatment" on linux work?
I know there is a "variable" called errno that is set when a error about
something happens and that I can read this value through perror, (at least I think it works that way) but how it really works I have no idea. So any tip on this subject will be nice.

Ever asked to man?

$ man errno

My 2ct.

Regards,

Signature · 1 line
wwp
#3 lore raw
In reply to r_zaca
Quoted 6 lines · r_zaca

Can anybody sugest me a good documentation about how all the functions
related to "error treatment" on linux work?
I know there is a "variable" called errno that is set when a error about
something happens and that I can read this value through perror, (at least I think it works that way) but how it really works I have no idea. So any tip on this subject will be nice.

If you need to check for specific errors, you can just check the value of errno, e.g.

	#include <errno.h>

	...

	if (do_something() == -1)
		if (errno != EAGAIN)
			perror("...");

The man page for a function should tell you which errors can occur.

Most of the time, you only care about whether an error occurred, not which error.

The most common errors to check for are EAGAIN and EINTR, which indicate "transient" errors (i.e. if you try again, the call may succeed). EAGAIN occurs when you try to read() from a non-blocking descriptor when no data is available. EINTR occurs if a system call is interrupted by a signal.

If you just want to report the details to the user, you can use perror() to print an error message to stderr which includes a description of the last error. If you can't use perror() (e.g. if you're reporting the error via syslog(), you can use strerror() to obtain the description string for a given error).

In most situations, you can treat errno as a simple integer variable; you can read its value, assign a new value, or take its address. However, with glibc 2.x, it's actually a macro:

	#define errno (*__errno_location ())

The reason for this is that, with multi-threaded programs, each thread has its own "copy" of errno.

One consequence of this is that you can't take its address at compile time, i.e.:

	static int *errno_p = &errno;

won't work.

Signature · 1 line
Glynn Clements <[email protected]>