Who has to look: exceptions, Results, and the bail-out law
Error handling across languages is one question in three costumes — who is forced to confront the failure?
Error handling across languages looks like a syntax war: try versus ?, Go's if err != nil, Java's checked exceptions. Strip the keywords and it's one question: who is forced to confront the failure? A language's answer shapes every function you write in it, and the field has exactly three answers.
Exceptions transport a failure from where it happens to wherever someone remembered to catch it, unwinding the call stack on the way. The error path is the path the source does not mention, which is the appeal and the danger in the same breath. Python, Java, C++, and JavaScript all live here.
Errors as values hand the failure back as an ordinary return value, written out in full next to the success path. Go's (result, err) pair and C's return codes are the model; the verbosity is the point. Result types go further and encode the failure in the return type itself, so the success value is locked behind the error case. Rust is the pure expression of that idea. TypeScript's discriminated unions and Python's Optional reach toward a weaker version of it.
Exceptions ask the caller for nothing. Returned values ask politely, and can be brushed off. A Result asks at compile time, and will not be brushed off.
- Exceptions — the error path is the code the source does not mention
- Errors as values — written out in full, verbose on purpose: Go's (result, err)
- Result / Option — failure lives in the return type; ignoring it is a compile error
the field is converging on ? — Go's visibility, with the guarantee kept.
How the failure travels
Propagation is where the philosophies actually feel different day to day. Exceptions propagate for free, no code per layer, and that's the whole appeal. Errors as values propagate manually, every Go layer writing the same ritual by hand. Result types propagate with an operator: it feels free and keeps the compiler's guarantee.
| Language | Propagate the failure up one layer | What the compiler enforces |
|---|---|---|
| Python | nothing — raise propagates automatically | nothing; an uncaught exception unwinds to the top |
| Java (unchecked) | nothing — propagates automatically | nothing |
| Java (checked) | throws IOException on the signature | the caller must catch or re-declare |
| C++ | nothing — throw propagates, destructors run | nothing, unless noexcept is violated |
| TypeScript | nothing — throw propagates | nothing; the catch binding is unknown |
| Go | if err != nil { return err } | nothing — _ can discard it |
| Rust | value? | everything — handle it or propagate it, or it won't compile |
Read the bottom two rows together and the settlement comes into view. Go makes you look, but lets _ look away for you. Rust refuses to let you look away at all.
One fault, two timelines
Same bug: a file read fails two layers down. In the exception world the frames in between say nothing — a function ten layers up can catch an error thrown ten layers down, and not one of the frames in between needs to mention it. In the Result world every frame on the way up had to decide, visibly: handle it, or pass it along. Flip between the two timelines of the same failure:
- main → parse — read_config()
- parse → read — open file
- read → parse — throws
- parse → main — sails through unseen
parse never mentions the failure. Nothing obliges it to.
- main → parse — read_config()
- parse → read — open file
- read → parse — returns Err(io)
- parse → main — Err — parse had to decide
same fault. parse had to acknowledge it before anything moved.
Zoom out and the whole argument fits in three numbers:
The operator that settled it
The ? operator is the most copied idea in modern error handling, and it's easy to see why. Unwrap if Ok, return the error up if Err — Go's entire ritual, gone. It only compiles inside a function that itself returns Result or Option, so you can't propagate a failure into a place with no way to receive it. And because ? converts through From, a low-level io::Error can surface as your own error type without a manual mapping layer at every step.
fn load_port(path: &str) -> Result<u16, io::Error> {let text = fs::read_to_string(path)?;let port: u16 = text.trim().parse().map_err(|_| io::Error::other("not a valid port"))?;Ok(port)}
The success value is locked inside Ok. The two ? lines are the whole propagation story. Adapted from Applied Computer Science.
Panic is not control flow
Every model also keeps an unrecoverable channel: panic, abort, assert. The law for it is short. It exists for invariant violations where continuing would corrupt state — a null where one was structurally impossible is a bug worth crashing on. A missing config file is a value. The unrecoverable channel is never control flow.
The working answer: which channel, when
| Reach for | When |
|---|---|
| Exceptions | failures are genuinely exceptional, the happy path dominates the reading, and the layers in between have nothing useful to say about the error |
| Errors as values | failure is ordinary and expected — network services, parsers, pipelines — and every caller should make a decision |
| Result / Option | a swallowed error or a null dereference is the bug you cannot afford; correctness is worth the ceremony |
| panic / abort | invariant violations only, where continuing would corrupt state — never control flow |
So which model wins?
Each one is the right default somewhere. Exceptions when failures are genuinely exceptional and the happy path dominates the reading — sometimes a throw really is the cleanest way to exit several layers at once. Errors as values when failure is ordinary and every caller should decide. Results when a swallowed error is the bug you cannot afford. What the field has stopped arguing about is the direction of travel.
Your service boots, reads its config file, and the file isn't there. Which channel?
- jameshu.io — Applied Computer Science, Error Handling: the three-models framing and the propagation table
- doc.rust-lang.org — The Rust Book on recoverable errors with Result
- doc.rust-lang.org — core::result, Result<T, E>
- rs4ts.dev — the error-propagation pattern: ? and From
- claudioromero.com — checked exceptions vs Results, and the bail-out flexibility Rust gives up