Hacker News new | ask | show | jobs
by Zambyte 391 days ago
I'm not as familiar with the Rust ecosystem, but I know it is used all the time in Go. For example, the standard http server library wraps user provided endpoint handler functions with panic handlers.
2 comments

I suppose it's a matter of perspective but I don't see returning a 500 as "Recovering from the error". The user's request has still failed. It just hasn't taken down the server. IMO this is still fine.
It is quite literally using the "recover" function in go, so I think it's accurate to call it "recovering".

> this is fine

I didn't mention the merit, just that it is exception style control flow.

Reading my top level comment again, I realized I did refer to the Zig way as "nice" relative to the exception style control flow.
Is that used for application-level errors though? Rust web servers do that too, but it is used a fallback to avoid bringing down the whole server due to an unexpected crash. It is not a mechanism you would use intentionally.
Probably not. I have never used panic / recover in application code at least.
encoding/json uses uses exception handlers for control flow.