Fix bug that checked for null rather than caught exception.