Chapter    12

Handling Errors

You’ve learned a lot about C. You’ve learned about arrays, pointers, dynamically allocating memory, and accessing files. Along the way, we’ve hinted at some of the pitfalls you have to look out for: not storing values outside the dimension of an array, not using uninitialized pointers, checking fgetc() for EOF, and so on. But we haven’t really been doing this in any systematic way.

Error handling is a general term for writing code so it still works when unexpected things happens. And believe us, unexpected things will happen. Your code isn’t battling for survival in the inevitable zombie apocalypse, but your program does need to defend itself from erroneous values, unexpected circumstances, and (yes) even hackers. ...

Get Learn C on the Mac: For OS X and iOS, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.