Exception handling for empty sequences