9 ms·
> Implicit exception propagation (like Java I haven't touched Java in 10 years, but didn't it have explicit propagation with `throws` statement for this exact
by golergka 6y ago
> Implicit exception propagation (like Java
I haven't touched Java in 10 years, but didn't it have explicit propagation with `throws` statement for this exact purpose?
- bluejekyll 6y agoThere’s always the feared NumberFormatException which is unchecked, for some crazy reason. Similarly, all unchecked errors and exceptions mean that you never know. So you have to treat critical sections of code as areas where resources need to be cleaned up by using try and finally blocks.
- masklinn 6y agoJava has both checked exceptions (explicit `throws`) and unchecked (no explicit notification), and its checked exceptions are often avoided because the delineation is not very good and they're cumbersome to work with.
- devit 6y agoI mean the fact that you in Java, etc. any function you call may throw an exception, which automatically propagates upwards from the code that calls the function, which results in part of the code in your function being executed and part not being executed, without any obvious signs of that (like having an early return or a "?" in the function). If the exception is not a RuntimeException and not declared in the throws clause, then the compiler will error out, but in other cases the code will compile. In Rust, you need to use the "?" operator when you call an exception-throwing function to propagate the exception, and if you don't you will get a Result, and a warning if you don't use it (i.e. not using "?" in Rust is like using Try in Scala). If Rust code has no "?" or "return", then no exceptions will be thrown and the code will fully execute, except for aborts and panics which are guaranteed to make all visible memory inaccessible, so you will never see a partial modification of an object due to an unexpected exception being thrown.
- mmebane 6y agoHow common is the ? operator in modern Rust code? I feel like if you reach a point where almost everything returns Result and almost every call is qualified with a ?, the pattern has turned into something that's not much different from checked exceptions.
- dralley 6y agoIt is pretty common, but Rust gives you a lot of tools to handle errors in-place more easily than other languages as well. I'd still consider it a significant improvement over checked exceptions in the vast majority of situations.