3 ms·
"I wonder whether there is an imperative language that enforces explicit handling of errors..." Java does that. If a method can throw an exception, you need to
by greenyoda 11y ago
"I wonder whether there is an imperative language that enforces explicit handling of errors..."
Java does that. If a method can throw an exception, you need to either handle the exception in a 'catch' block or throw it up the call stack for another method to handle. If you do neither, your code won't compile.
- lost_name 11y agoBasically. You need to handle all checked exceptions (Exception class), but not unchecked exceptions (RuntimeException class).
- ufo 11y agoThe problem with checked exceptions a-la Java is that the type system is not polymorphic. You need to list the exceptions you raise explicitly and there is no way to say "I raise the same exceptions that this object I receive can raise"
- placeybordeaux 11y agoIn the second paragraph the author seems to be only talking about errors as C and go have then, specifically as errors as values, not as exceptions. The important difference being that exceptions can occur anywhere and can lead to non explicit bailing out of a function. Exceptions complect failure and control flow. Judging from the docs (and the comments on the blog) it looks like rust might have largely what the author is looking for. Can anyone speak to that?
- snuxoll 11y agoRust handles errors in a functional-style way with std::result<T, E>. This is the same technique I use in F# code with a identically named discriminated union.