Catch error correctly in cursor when checking out a new connection