Removing exit(1) and using throw