Error handling for invalid inputs