Explanation
try block:
-
Python runs the code inside the try block first.
print("Hello") executes normally, so it prints:
-
Then, raise Exception is used to manually raise an exception. This immediately stops the normal flow and jumps to the except block.
except block:
-
Since an exception occurred, the code inside the except block runs.
-
It prints:
✅ Final Output:
This shows how Python handles exceptions:
-
It tries the code.
-
If something goes wrong (an exception is raised), it jumps to except and handles it.
0 Comments:
Post a Comment