Refactored to use try/catch on input validation.