Talk:C Programming/Error handling

Untitled
too far stretched an intro it becomes. Compilation overview is great but this... should go somewhere near the end

int dividend = 50; int divisor = 0; int quotient;

if(divisor == 0) { // Handle the error here... }

quotient = (dividend/divisor);

// Handle the error here...

Handle the error with what code? Please. --193.77.22.121 16:41, 27 July 2006 (UTC)

Where the problem usually is if there comes an message "command not found"? --212.149.219.87 14:30, 15 May 2007 (UTC)

Don't have to answer. Problem solved. - 212.149.219.87 15:51, 15 May 2007 (UTC)

I have made several edits. is defined to be 1 in C (not in C++ though), so I removed it from the call to  and forced the arg type passed in to be an   (even though the compiler would probably assign it that type). is not always set if  fails so the code now displays a hard-coded message. The code was returning 1 to indicate failure which is a bad idea, it should return the value  (which may be 1, or it may not, it's implementation dependent - on VAX/VMS systems 1 indicates success). 0 can be used for successful exit (in VAX/VMS that is converted to 1 and returned) or. I've added a space after each use of  as a stylistic hint that it is not a function call. I'm assuming this C book is teaching Standard C as much as possible because I notice specific mentions of UNIX etc. where non-Standard use of C is demonstrated, which is good. -- Mickraus 23:58, 27 October 2007 (UTC)

The first example
In the first example, why are the directives:

used at all?
 * #include  and
 * #include 

The function call "strerror( errno )" is never made in the example code, even though it is mentioned in the preceding paragraph.

On a slightly unrelated topic, I ran the example code, and received a malloc failed response.

I have 8 GB of RAM on my system.My OS is 64 bit windows 7. I think it should be mentioned in the comments of the example; or in an appropriate place in the preceding text; that this example will (most likely) fail if you have less than 2 gb of RAM on a "32 bit system". And most likely this example will fail if you have less than 16 gb of RAM on a "64 bit system".

V-a-xvi (talk) 03:12, 23 November 2010 (UTC)


 * I just ran a modified version of this example and it works as expected, and I assume that its an oversight in the example that the line puts(strerror(errno)) is not included. I've corrected the example as I think appropriate.


 * V-a-xvi (talk) 19:35, 24 November 2010 (UTC)

Pointers
You include code that uses pointers before you ever introduce the concept of pointers. I think this is likely to be confusing, even though people can always read ahead or google it. Finsternish (discuss • contribs) 19:03, 24 August 2015 (UTC)

Signals
The signals section here is very incomplete; it starts off well, but then suddenly ends before explaining how `signal` actually works, or even its syntax, or what `SIGINT` is, etc., which leaves the reader with a useless example (that would be useful if explained).

As with my other comments, I'll come back and fix it once I understand it. :) Meatnordrink (discuss • contribs) 14:08, 13 January 2021 (UTC)

Agreed, the signals section leaves a lot to be desired. Furthermore, please stop using functions that are not signal-safe in signal handlers. In particular, printf and exit are not safe to call there! --188.98.119.31 (discuss) 09:15, 22 March 2021 (UTC)