CIC Hands On Python - s4
CIC Hands On Python - s4
Try Block:
The try block contains the code that might raise an exception. You
place the code that you think might raise an exception inside the
try block. If an exception occurs within the try block, Python
immediately jumps out of that block and into the except block.
Except Block:
The except block contains the code that is executed if a specific
exception mentioned in the except statement occurs in the
corresponding try block. You can catch specific exceptions or catch
more general exceptions.
Note: you need to place your exceptions With a hierarchy from the most important to the least
else: Contains code that executes only if no exceptions occur in the corresponding try block. It is optional.
finally: Contains code that always executes regardless of whether an exception occurred or not. It is optional.