Thursday, February 24, 2022

Python exception handling

 A Comprehensive Guide to Handling Exceptions in Python

python-textbok.readthedocs.io

Errors and exceptions


eg -

import sys


randomList = [1, 2, 8]

for entry in randomList:

    try:      

          print(randomList[entry])

    except:

        print("Oops!", sys.exc_info()[0], "occurred.")


Output

22
8
Oops! <class 'IndexError'> occurred.

No comments: