5 ms·
Exactly. I have exactly two panics in my ~15k line server. Both are in initialization code that will probably never get called, so it will fail very early on i
by beatgammit 13y ago
Exactly.
I have exactly two panics in my ~15k line server. Both are in initialization code that will probably never get called, so it will fail very early on in the code. The rest of my code looks like this:
func getRecord(args...) (err error) {
if err := doSomethingRisky(); err != nil {
return err
}
if err := doSomethingElseRisky(); err != nil {
return err
}
... other code ...
return nil
}
func processRecord() error {
if err := getRecord(args...); err != nil {
return err
}
... do other stuff ...
return nil
}
All the way down the stack. It's certainly a little more code, but it forces you to at least acknowledge all errors. If you want a stack-trace, you can always use the runtime package.
- burntsushi 13y agoNo, this isn't what I'm talking about. See my response: https://news.ycombinator.com/item?id=7222197 https://news.ycombinator.com/item?id=7222197