8 ms·
> 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,
by 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.