I know this topic has been done to death, but this example could be symptomatic of ergonomics with try...catch rather than guard.
Often I want to try a throwing function and act if it throws but I don't care what the actual error was. Instead of writing:
do
{
try something()
}
catch
{
// Respond in some way, perhaps throw another error or return nil.
}
it would be nice if it could just be:
try something() else { /* do something else */ }
which looks a lot like what the OP is wanting to do.
I'm rarely a fan of shorthand in programming languages, but this would remove some noise from the listing.
A related scenario is when wanting to try one thing, and only if that fails then try something else, perhaps trying two or three different fallbacks, and then only if all of them have failed then you do a final catch. Perhaps there's an idiomatic way of expressing such a chain succinctly, but the naive way seems to be lots of dos and catches.
Interestingly we already have a precedent of simplifying a similar pyramid of doom with "if" statements. Following that precedent gets us to this alternative:
do { // as in "if"
try oneOfSeveralThrowingFunctions()
} catch do { // as in "else if"
try oneOfSeveralThrowingFunctions()
} catch do {
try oneOfSeveralThrowingFunctions()
} catch { // as in "else"
print(error)
}
I still like the simplicity of a simplified try foo() catch bar() without a do.