EDIT: re-reading what I wrote here, I think it may have come off more accusatory/harsh than I intended. I only intend to point out my strong feeling that “try”/“catch” or related words just don’t feel right (to me) and I’m wondering how much of the support for “try” (or “catch”) comes from just feeling it should be what is used because it is generally what is used as opposed to having a strong feeling one way or the other.
I’m still not sold on the idea of using “try”. It seems to me that:
let x = whatever_keyword_is_chosen {
let y = something_else(something?)?;
process(y + 2)? * 3
};
Is really a short-hand for:
let x = ApplyLambda( || {
let y = something_else(something?)?;
process(y + 2)? * 3
});
Which, again, argues for using something like “returned” or “resultof” to emphasize the notion that Rust handles error conditions by returning Error/Fallible values or the desired Value from functions, not by raising errors, stack unwinding, etc.
NOTE: In the above I’m using some pseudo-code just to convey the notion of what I’m getting at.
I honestly feel like everyone arguing for “try”, “catch”, etc. wish (perhaps without even being completely aware of why) that Rust just had exceptions like other languages and really don’t like the fact that Rust uses Result<T,E> etc. It seems like everyone just wants to make it look like exceptions in other languages even though it isn’t. Maybe it is even subconscious (i.e. “it feels like it should be that way because that is what [we’re] used to”).
Personally, I really like the direction of Rust error handling and think it makes sense to emphasize the fact that it is returning value/error not raising exceptions/stack unwinding.
In fact, because “Panic!” is effectively an “Exception” that can’t be caught (akin to a RunTime exception in Java that shouldn’t be caught with the additional restriction that it CAN’T be caught, except at a thread boundary) that making it absolutely 100% clear that Rust error handling ARE NOT exceptions is the most advisable thing to do.
Again, this is just my opinion, but, and opinion I strongly hold. I would ask everyone to really consider why they want something like “try”? What makes you lean in that direction? Is it justified by the nature of what Rust is doing/embracing or is the only justification some notion of using terminology familiar to other exception-based languages? If the latter, why is that a good thing? Really think about it.