C errors/exceptions

From wikinotes


system errors (errno/perror)

When syscalls produce errors, they return -1, and set the global constant errno. <errno.h>'s perror is a function that when provided with an errno, returns the error that was produced.


See man errno for a list of exit() codes and their meanings.


#include <errno.h>

void error( const char *message ){
	if (errno) {
		perror( message );
	} else {
		printf("ERROR: %s\n", message);
		exit(1);
	}
}


exceptions

C does not have any exceptions.