Wrap least squares fit in a try block