3 ms·
I agree with the panic sentiment. I almost never know when to actually use panic or to just return an error code. My guess is the reason panic is never used is
by nemothekid 13y ago
I agree with the panic sentiment. I almost never know when to actually use panic or to just return an error code. My guess is the reason panic is never used is because its "bad go" for a panic to leave your library/package.
http://golang.org/doc/effective_go.html#panic http://golang.org/doc/effective_go.html#panic
- ansible 13y agoGenerally speaking, you ought to use error instead of panic. The only time panic is appropriate is when the program really ought to just crash. For example, I'm writing a small program to update a database. If the DB connection can't be opened, the program can't do anything useful, so it can just exit with an error. Any library should just use error.
- voltagex_ 13y agoWhy isn't lack of DB connection a panic condition?