Error catching

Catching a couple of errors, and treating the SUM(1) as a string then
cast into integer