Hacker News new | ask | show | jobs
by lcedp 4712 days ago
But wait! Shouldn't file system subroutine check if it actually written what was asked thus marking operation as completed successfully.

Why do we have bloody exceptions if we need to double check every action taken?

3 comments

I actually find it much easier to code reliable stuff in C where you have to check error conditions manually. If for no other reason that it serves as a constant reminder that the failures happen, and if you're writing reliable software this forces you into consistent habits to handle them.

I feel like in a language with exceptions, since throwing and catching happens inconsistently and haphazardly all around a code base, people are conned into thinking the exceptions will never happen. Usually one of two things happen:

1. The language is like java and it forces you to declare what exceptions you throw, so lazy people just put in lots of do-nothing catch blocks to silence the compiler.

2. The language doesn't have the "checked exceptions" concept, so people literally think no exceptions can happen. They just wait for the exception to make everything blow up.

Often when exceptions are handled, this lack of explicitness makes sure it's done at totally the wrong stack frame to make the judgement call about what to do about it. Then some people do dumb shit like try to catch things like stack overflow exceptions which should rightfully take down the process, and keep running. Not to mention that an exception is just a wacky concept, it's essentially a goto that crosses stack frames... Everyone criticizes goto, but few people will question exceptions...

This is actually the reason exceptions were created - in some languages, such as C, there are no exceptions and so the result of each write needs to be manually checked for errors.

If you're using a language with exceptions, your program will halt if it can't write. If you're using a language with checked exceptions, you'll have to write code to deal with any possible exception that can be thrown.

A lot of code doesn't have exceptions; it might, for example, be written in C, or C++ in a place where exceptions aren't used. fprintf() and friends don't raise exceptions on failure.