News for hackers. Stuff that matters.
Re:Cloudflare outage on November 18, 2025 post mortem by gwbas1c on Tuesday November 18, 2025 @09:59PM (#45975354)
It's a lot lighter: a stack trace takes a lot of overhead to generate; a result has no overhead for a failure. The overhead (panic) only comes once the failure can't be handled. (Most books on Java/C# don't explain that throwing exceptions has high performance overhead.)

Exceptions force a panic on all errors, which is why they're supposed to be used in "exceptional" situations. To avoid exceptions when an error is expected, (eof, broken socket, file not found,) you either have to use an unnatural return type or accept the performance penalty of the panic that happens when you "throw."

In Rust, the stack trace happens at panic (unwrap), which is when the error isn't handled. IE, it's not when the file isn't found, it's when the error isn't handled.

Re:Cloudflare outage on November 18, 2025 post mortem by dehrmann on Wednesday November 19, 2025 @01:57AM (#45976613)
> a stack trace takes a lot of overhead to generate

Can't Hotspot not generate the stack trace when it knows the exception will be caught and the stack trace ignored?

Re:Cloudflare outage on November 18, 2025 post mortem by mike_hearn on Wednesday November 19, 2025 @09:01AM (#45979587)
It can and that optimization has existed for a while.

Actually it can also just turn off the collection of stack traces entirely for throw sites that are being hit all the time. But most Java code doesn't need this because code only throws exceptions for exceptional situations.

Re:Cloudflare outage on November 18, 2025 post mortem by branko_d on Wednesday November 19, 2025 @02:26AM (#45976773)
> Exceptions force a panic on all errors

What do you mean?

Exceptions do not force panic at all. In most practical situations, an exception unhandled close to where it was thrown will eventually get logged. It's kind of a "local" panic, if you will, that will terminate the specific function, but the rest of the program will remain unaffected. For example, a web server might throw an exception while processing a specific HTTP request, but other HTTP requests are unaffected.

Throwing an exception does not necessarily mean that your program is suddenly in an unsupported state, and therefore does not require terminating the entire program.

Re:Cloudflare outage on November 18, 2025 post mortem by frumplestlatz on Wednesday November 19, 2025 @04:32AM (#45977575)
> Throwing an exception does not necessarily mean that your program is suddenly in an unsupported state

When everyone uses runtime exceptions and doesn’t count for exception handling in every possible code path, that’s exactly what it means.

Re:Cloudflare outage on November 18, 2025 post mortem by branko_d on Wednesday November 19, 2025 @09:56AM (#45980327)
Sure, but the same is true of any error handling strategy.

When you work with exceptions, the key is to assume that every line can throw unless proven otherwise, which in practice means almost all lines of code can throw. Once you adopt that mental model, things get easier.

Re:Cloudflare outage on November 18, 2025 post mortem by frumplestlatz on Wednesday November 19, 2025 @10:10AM (#45980502)
Explicit error handling strategies allow you to not worry about all the code paths that explicitly cannot throw -- which is a lot of them. It makes life a lot easier in the non-throwing case, and doesn't complicate life any more in the throwing case as compared to exception-based error handling.

It also makes errors part of the API contract, which is where they belong, because they are.

Re:Cloudflare outage on November 18, 2025 post mortem by branko_d on Thursday November 20, 2025 @01:55AM (#45989737)
I would respectfully disagree with most of what you said. I guess individual perspective depends a lot on the kinds of code you work on.

The point about being explicitly part of the API stands, though.

Re:Cloudflare outage on November 18, 2025 post mortem by gwbas1c on Wednesday November 19, 2025 @11:58AM (#45981877)
> Throwing an exception does not necessarily mean that your program is suddenly in an unsupported state, and therefore does not require terminating the entire program.

That's not what a panic means. Take a read through Go's panic / resume mechanism; it's similar to exceptions, but the semantics (with multiple return values) make it clear that panic is for exceptional situations. (IE, panic isn't for "file not found," but instead it's for when code isn't written to handle "file not found.")

Even Rust has mechanisms to panic without aborting the process, although I will readily admit that I haven't used them and don't understand them: https://doc.rust-lang.org/std/panic/fn.resume_unwind.html