Added checks for error being nan or inf. Re #7182.