Added my attempt with exception handling