I'd argue that is not a direct equivalent. Like @binarycat, to me throw
reads "nonlocal exception", that will be caught and handled anywhere up the call stack, whereas in Rust it will always only go to the immediate surrounding try
or function block, and no further.
Since we are already bikeshedding, my vote would be for error
(or even just err
if we are lazy in typing), since Err
results is what we are constructing:
let Ok(val) = validate(expression) else {
error format!("{expression:?} is invalid!");
}
Not to mention it'd give me fuzzy, warm, nostalgic BASIC vibes