Is there a way to recover from `ensure` blocks in ...
# arrow
c
Is there a way to recover from
ensure
blocks in the raise dsl?
y
Well,
recover
exists. But likely you want to use any of the myriad of other builders to recover.
c
My intuition would be to do something like
Copy code
ensure(...) {
  recover {
    // ...
  }
}
but that’s probably not right
y
Oh, I see you. I mean, you can do non-local returns inside
ensure
, so you could do something like:
Copy code
someFunction {
  ensure(...) { return@someFunction ... }
}
But at this point, why not just use
if(!condition) ...
c
I have a case where I want to ensure a locally stored value isn’t null, but if it is, I want to invoke a function that fetches it remotely and proceeds 🤔
y
That's just
?:
lol I think you could be experiencing a golden hammer problem?
c
Entirely possible
I’m simplifying things a bit for the sake of an example, but it’s entirely possible I’m overthinking it
y
Not intending any disrespect or anything of course to be clear, just saying that I think it's good to thing of ensure as
if (!condition) raise(block()
and hence if you want "variations" on it, you likely want an
if
statement
c
No worries; thanks for the advice