4 ms·
I don’t like Go error handling, but exceptions are terrible and not better. Rust/Zig/Swift approach is definitely the best.
by cjglo 4y ago
I don’t like Go error handling, but exceptions are terrible and not better.
Rust/Zig/Swift approach is definitely the best.
- kaba0 4y agoExceptions are much better, especially checked ones (which are analogous to Rust-style result types).
- cjglo 4y agoNot analogous. Rust-style result types continue the normal control flow. Any exception thrown deep into a function can be very hard to debug. The normal line of execution is stopped, even without a return, and if it’s a checked exception it can “bubble up” to higher functions despite nothing signifying a return, just a marker saying somewhere this can throw an exception. Exceptions are terrible.
- kaba0 4y agoThis is literally the exact same thing. Exceptions are not gotos. They bubble up one method at a time, and can be handled at any level you want. Matching on a result type is literally the same thing as putting in inside a try-catch block. Putting a ? macro at the end is literally the default behavior. You can handle it on as tight/wide scope as you wish, plus you also get a must-have stacktrace — so your debugging is just looking at where the exception originated from.