Refactored: Uses specific exception and adds documentation.