Hacker News new | ask | show | jobs
by debo_ 951 days ago
In OCaml the type checker won't force you to handle exceptions (from what I remember.) See e.g. https://ocaml.org/docs/error-handling#exceptions
1 comments

That's true, but at least in my experience, it is rarely a problem. Because if you're at a point in your program where you don't want to bubble up, you can just pattern match against the exceptions just as you would a Result type, which F# also has.

I don't know Rust, but after searching, it seems that it has a panic facility which seems even more escaping than an exception. Happy to be corrected there.

`panic` has nothing to do with error handling though. If you use it, you know that your callers cannot recover from it.

Throwing an exception implicitly delegates error handling back to the caller, but they are not even notified about it. (talking about OCaml)

No, they can, check the catch_unwind API.

Some frameworks catch panics automatically. For example, in the Actix web framework, if you panic in an HTTP response the panic will be catchee, so it won't bring the whole server down.

Also, by default a panic will terminate only the current thread, which is a major footgun: you now need to reason about what you program will do after some bug or unforseen circunstance happened somewhere in the code and made you program misbehave. Which leads to slightly insane things like lock poisoning.

It's more sane to compile with panic=abort, but that's not the default and it means that on panic you won't release resources (which aren't just allocated memory to be clear)

Yeah. I don't find it to be a problem either, but the parent does and I can see where they are coming from. Even Java has checked exceptions.