solutions with exception handling