3 ms·
> Of course, if you’re the sort of person who deals with errors in rust by just slapping ? on anything that might fail, then you’re more or less just doing exce
by jgilias 3y ago
> Of course, if you’re the sort of person who deals with errors in rust by just slapping ? on anything that might fail, then you’re more or less just doing exceptions
Well, no, not really. You typically still explicitly enumerate how your code may fail to use that notation (unless it’s a small utility where you just anyhow it), you also have the fallible values clearly denoted as such, and not everything is fallible. And last, but not least, every time I slap a ‘?’ I tend to quickly evaluate what the failure case is, and if it’s something I can’t do anything about at the moment and should just bubble up, or is it something I can actually handle.
So, no, not the same thing as exceptions at all!
- Zamiel_Snawley 3y agoAnd also, returning errors by value does not introduce hidden control flow! In python, you have no way of knowing what(if any) exceptions that a function may throw, so unless you catch everything you have no way of knowing where execution will end up after calling a function. Not to mention the intentionally(!) thrown exceptions for iterators. In my book, exceptions are goto by another name.
- diarrhea 3y agoExceptions are goto in disguise to some extent, as it’s forward-jumping only. An important limitation to retain structured programming in this case.
- dumdumchan 3y agoI could show you 20 functions in stdlib itself and popular libraries that return an error but don't mention under what circumstances. They have an internal error type that is a catchall and this isn't exactly an upgrade over exceptions.