Conceptual
Login

Returning Errors with Result and the Question Mark Operator

Result is the type a function returns when it might fail: either the value you wanted or an error describing what went wrong. The question mark operator says "if this failed, stop here and pass the error up to my caller", which keeps the successful path readable. Without it, error handling either buries the real logic or gets skipped entirely.

Questions this Concept answers

  • Why does `?` make failure-heavy driver code easier to read than checking each call by hand?