added a try catch method instead of just throwing the exception