Check AutoDiff return code 

Fail fatally if automatic differentiation returns an error. Closes #4058.