Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think what people usually mean in these situations is that you’re forced to think about the error.

Programs in C (and many other languages) have the problem that you can ignore errors accidentally.

Exceptions “solve” this by forcing some level of your stack to at least acknowledge that an error occurred. The problem with that model is that you still don’t have to think at any given level of the call stack what the appropriate handling is for any kind of error. You can just let it propagate up further, deferring responsibility.

For some code that might actually be appropriate, but often it results in code higher up that cannot possibly know how to deal with every error that can happen farther down the call stack just swallowing errors.

One thing I frequently see is mixing validation code with processing logic. By separating the two you can have the validation code deal with errors and the logic simply assert that it’s input is good (because it should have been validated by the error handling code before being passed in).

I think models where you are forced to think about errors at each level but have a simple mechanism to make them propagate up are probably the best single model if you have to choose one model for a language.

In any event, error handling is difficult and frequently doesn’t get the attention it deserves in the design and implementation of libraries and large systems.



In my experience, the vast majority of error handling has been essentially limited to bubbling the error up, cleaning up unmanaged resources, and either re-trying the operation with some back-out logic or giving some details to the user about what happened and letting them decide what the best thing is.

I have very rarely seen something useful to be done by code automatically to recover from an error, other then re-trying. As such, I feel that the way Go makes you constantly write error-handling code is counter-productive, since it forces you to think about something that really doesn't need that much thinking about.

And as I said earlier, the deluge of non-handling error handling code can serve to mask the rare cases where errors are actually handled in some tricky intelligent way.


You can ignore an error in Go simply by ignoring its return value. Sometimes it's difficult to tell a foot-gun and land-mine apart.


you can swallow an exception in java by simply having an empty exception case.

Exceptions are certainly more robust, but purposely ignoring errors can be done with exceptions too.


Ignoring errors silently, regardless of intention, can't be done with exceptions.


    try {
        // do stuff
    } except( Exception e) {  
        // ignore
    }

and yes, I've seen it often.

I will agree that it's not possible to accidentally ignore an exception, since it will likely crash your application.


That's not silent, it's screaming in the code.


that's only if you find it in the code


I thought we were talking about code though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: