Added an error handler to the primeFactors function