Linked by Eugenia Loli-Queru on Fri 8th Sep 2006 04:08 UTC
General Development Proper error detection and recovery is often ignored by UNIX developers. The lack of exceptions from the C language and the rudimentary error mechanisms from the standard C library certainly contribute to this. This article familiarizes you with the UNIX standard error reporting mechanism, the errno global variable. You'll also learn about a couple of associated global variables ( sys_nerr and sys_errlist) and the standard functions that help you report errors to the user and (hopefully) encourages you to report and handle errors in a user-friendly way.
Thread beginning with comment 160627
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Well, ...
by gilboa on Fri 8th Sep 2006 21:46 UTC in reply to "Well, ..."
gilboa
Member since:
2005-07-06

... Yeah, sure, exception is much more powerful.

If you need fine grained error recovery, instead of doing:


int err;
..
if ((err = command(...)) < 0) {
/* Fine grained error recovery. */
err = errno;
goto out;
}


You do:


int previous_err = 0;
int err = 0;

...
if (!previous_err) {
try {
command(...);
}
catch (...) {
// Fine gained error recovery.
...
// No goto. We don't do such things in
// CPP. Lets us just do if previous_err
// 128 times till the end of the function.
previous_err = err;
}
}


<SARCASM>
Yep, indeed C++ exception is much better at fine-grained error recovery then C
is.
Thank God kernels and OS libraries are still written in C!
</SARCASM>

- Gilboa
* Sorry about that... I'm just faced, on a daily basis, by herd of C++ programmers who throw C++ on each stupid error, failing to do any type of error recovery and leaving all the clean up to the CPP/C libraries/drivers/etc.

Edited 2006-09-08 21:47

Reply Parent Bookmark Score: 1

RE[2]: Well, ...
by Legend on Sat 9th Sep 2006 10:59 in reply to "RE: Well, ..."
Legend Member since:
2006-07-27

Ugh, sorry, that doesn't seem good C++ style to me. I don't just catch errors and then later figure the errors out again by a lot of if-statements.

Reply Parent Bookmark Score: 1