Refactored to use custom exception.