3 ms·
I 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 functio
by devit 6y ago
I 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.