News for hackers. Stuff that matters.
Re:Go proposal: Leave “if err != nil” alone? by ljm on Friday June 28, 2019 @03:13PM (#20307867)
I dislike exceptions for the same reason, because it’s often not clear if the error will come through an indirect channel (the exception), or in the return value. It’s better in languages that express that in their type system.

And unless you catch the common ancestor for all exceptions, it’s difficult to know what you need to look out for. This is especially true in dynamic languages like Ruby.

To my mind, exceptions enter a language when the language lacks the semantics to expose them in the return value, where true/false/null/errno is too primitive for larger systems.

Option, Result, and Either are great alternatives that allow you to propagate problems to deal with them at a higher level, with explicit acknowledgment that an error might occur.

Exceptions can be ignored and caught in random places with little to no context, so long as they’re further up the stack. Or you just get stuff like:

    try {
      Application->runTheWholeThing();
    } catch (e) {
      print “something went wrong”;
    }
Re:Go proposal: Leave “if err != nil” alone? by mey on Friday June 28, 2019 @03:25PM (#20307970)
I've been avoiding the discussion around Dynamic/Static s/types/languages/g , documentation/interface definition, and typed exceptions. If I go off on that rant, I'll be here all day.

If you are catching error in random places, you are doing it wrong. As you pointed out, context is critical. My point is generally, the location of code that generated the error may not have sufficient context. If you have enough context locally (or through further inspection) on how to proceed, then you handle it at that level. If you don't have enough context, then you send it up the call chain.

In your code example above, if after that catch, the program exits, then I argue it is correct. Some exception that was unrecoverable happened somewhere in the application, thus it needs to halt. If the error is recoverable and the application should continue, the exception should be handled somewhere else in the application.