refactored to use caught exception