8 ms·
> if a request / task panics ...and the condition why it panics is not a situation that warrants a crash, then whatever is called upon handling that request is
by usrbinbash 2y ago
> if a request / task panics
...and the condition why it panics is not a situation that warrants a crash, then whatever is called upon handling that request is issueing a panic when it shouldn't.
The reason why some libs do that anyway is exactly what I describe above: because in many peoples minds panic == exception.
That's a logic error in the code and should get fixed. And one of the best ways to make devs fix things, is to let their application crash when something that shouldn't happen happens anyway, because then someone will start complaining why a service is unreachable.
TL;DR:
If some condition shouldn't crash a process, it has no earthly business causing a panic.
- the_gipsy 2y agoYou're conflating unnecessary panics, with how to handle panics. There will always be panics. You don't need to crash the thing to make devs notice, they're not idiots no matter what Rob Pike told you. You can alert and not throw out the baby with the bathwater. Nobody wants panics in their code, even if they're not crashing the whole world.
- usrbinbash 2y ago> You're conflating unnecessary panics, with how to handle panics. I don't think so. If I have to handle a panic, because otherwise my program no longer works, one of 2 things is true in the vast majority of cases: - There is something seriously wrong with the program or its environment, causing it to panic - There is something in the program issueing a panic when really it should return an error In short: there should be no need to "handle panics" Panics are irrecoverable conditions where its preferable for the program to crash rather than continue. If code panicks for any other reason, thats, in my opinion, wrong, and should be fixed. Panics are not the equivalent to exceptions, and error returns exist for a reason. People who don't like that paradigm can always use a language that uses the exception-paradigm.
- the_gipsy 2y ago> People who don't like that paradigm can always use a language that uses the exception-paradigm. FYI the go std library recovers from panics when it spawns goroutines internally, in most cases. All this has next to nothing to do with exceptions. Nobody is saying to use panics to pass errors or any control flow.