Hacker News new | past | comments | ask | show | jobs | submit login

>It seems that having exceptions in the language is a great predictor for libraries/built-ins barfing upon bad input vs silently producing garbage

Maybe so, but having exceptions in a language is also a good predictor for the misuse of exceptions for purposes other than error handling. For instance, Python has the StopIteration exception to signal the end of an iteration.

Exceptions force API designers to decide whether or not a situation is exceptional enough to force a stack unwind on the caller's end. That's not something that's necessarily decidable from the point of view of the library.

For instance, say you have a function http.get(url). Should a 404 response automatically raise an exception? What about a 301? A network issue? Surely, for a crawler, a 404 is not exceptional enough to merit a hidden goto that unwinds the stack frame (by default). The designer of the http library cannot decide which status code is exceptional in every application.

It's similar with the results of SQL statements, file system access and all sorts of other IO related stuff.

It seems to me that the more complex a system is, the more it needs a very specific error handling strategy anyway and doesn't benefit from library designers' opinions about what is and isn't worth a stack unwind.

That said, I do hate seeing

  if err != nil {
    return nil, err
  }
on every other line of code.



> Maybe so, but having exceptions in a language is also a good predictor for the misuse of exceptions for purposes other than error handling.

Is that really a problem? I once hated such uses, but could never point why.


I think it's a problem for two reasons:

First of all, sudden stack unwind comes with a greater mental burden than regular structured code. Something implicit is happening that violates the expectations we have based on what we can see.

Secondly, consistency is always important because inconsistency forces us to think about things that we shouldn't have to think about, which lowers our productivity.


Don't worry, you won't see them that much since people will forget them.

That's the entire point of exceptions: never let an error get silenced.


Haha, no. You pretty much never forget them. And if you're worried, you can run a linter to find spots you've missed.

My go programs are 100x as robust as my programs with exceptions because Go actually forces you to think about the error path, not just the good path.




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

Search: