Crashing the program earlier has two advantages: the program is dead, and the resources are reclaimed by the system. A dead program is better than a crippled one. The Pragmatic Programmer
To do this, always check the return value of a function or method of a class with the expected value. Crash the program as soon as there’s a problem. Combining with some software engineering practices such as Design by Contract (DBC), it will give a strong guarantee that the system will not put up unexpected operations.
We can quickly do this using a macro function# :
#define CHECK(LINE, EXPECTED) \
{ \
int rc = LINE; \
if (rc != EXPECTED) \
ut_abort(__FILE__, __LINE__, #LINE, rc, EXPECTED); \
}
void ut_abort(char *file, int ln, char *line, int rc, int exp) {
fprintf(stderr, "%s line %d\n'%s': expected %d, got %d\n",
file,
ln,
line,
exp,
rc);
exit(1);
}