Hey Kyle. could you please elaborate a bit?
As far as I understand, the issue with Java/C++ style exceptions is the huge cost of stack unwinding in error cases, and the the associated binary bloat. I'm not advocating for that at all, and I much prefer the modern approach to errors in Swift/Rust.
That said, I think the checked and unchecked exceptions is Java is actually fantastic, e.g.
- For reasonably-recoverable errors (e.g.
NumberFormatException
), you can't throw without declaring it and forcing your caller to have to handle it - For other (e.g.
ArrayIndexOutOfBounds
) you can throw it without your caller needing to handle it, but they still can if they want to.
What's not to like about that? (At least in principle, the implementation approach is what sucks about it, IMO)
(edit: Ignore Java's typed throws. You can have the distinction between checked vs unchecked exceptions without needing the checked exceptions to also be strongly-typed. That's an orthogonal topic.)