Hacker News new | ask | show | jobs
by pixie_ 4683 days ago
Is there any way to 'catch' a divide by zero panic in go?
1 comments

For others: note that that's only because Queue29 assigned 0 to a variable before using it as the denominator, so there's no way for Go to catch that at compile-time.

If you divide by a literal 0, this is a compile-time error, so there's no panic (and no need to recover()): http://play.golang.org/p/E0jSDAHwtg

Interesting thanks. Of course then I was wondering what this recover() stuff was and I found an explanation here - http://blog.golang.org/defer-panic-and-recover cool stuff.