Handling overflow and division by zero