6 ms·
I can't really imagine 80% error handling for the whole codebase unless literally all of your functions look like this: int foo(Data *data) { int error =
by fasterik 3y ago
I can't really imagine 80% error handling for the whole codebase unless literally all of your functions look like this:
int foo(Data *data) {
int error = do_some_io_request(data);
if (error) log_error(error, "Request failed");
return error;
}
For propagating errors up the stack, the ratio is only 50%:
int error = foo(data);
if (error) return error;
For the rest of your code, I guess it's domain specific. But most projects should have a significant amount of the codebase doing things with data in memory that can't fail.
- AnimalMuppet 3y agoA lot of code looks like this: int handle = open(file, S_IREAD); if (handle == -1) return false; int size; if (read(handle, &size, sizeof(size)) != sizeof(size)) { close(handle); return false; } char *buffer = malloc(size); if (buffer == null) { close(handle); return false; } if (read(handle, buffer, size) != size) { close(handle); free(buffer); return false; } And so on, with the number of things you have to clean up growing as you go further down the function.