You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you want to continue running after a function call fails:
// Get first item from current `arr`
foo() ~ arr = clone(arr[0])
fn main(){
~ arr := []// `arr` is empty, so there is no first item.
a := foo()// ERROR: Out of bounds `0`println(a)}
A try expression lets you convert runtime failures into err and success into ok:
foo() ~ arr = clone(arr[0])
fn main(){
~ arr := []
a := try foo()println(a)// prints `err(...)`}
Try expressions are convenient together with the ? operator:
Sometimes you want to continue running after a function call fails:
A try expression lets you convert runtime failures into
err
and success intook
:Try expressions are convenient together with the
?
operator:This maps
err
to early returns, and runtime failures toerr
:The text was updated successfully, but these errors were encountered: