Jun-11-2020, 09:22 PM
To handle the issue, the operation that might throw the exception must happen in the try: block.
In your second example, that's exactly what is shown. There's only one line in the try block, and it's an explicit division by zero. So the except block is entered.
In your first example, the division by zero potentially happens in line 9 (since that's where the division occurs), not line 12 which prints the answer. By then, it's too late.
In your second example, that's exactly what is shown. There's only one line in the try block, and it's an explicit division by zero. So the except block is entered.
In your first example, the division by zero potentially happens in line 9 (since that's where the division occurs), not line 12 which prints the answer. By then, it's too late.