Python - Exception

Card Puncher Data Processing

About

Code - Exception (Try, Catch, Finally statement) in Python

Syntax

Exception handlers are specified with the try … except statement.

See:

Example

import sys

try:
    f = open('myfile.txt')
    s = f.readline()
    i = int(s.strip())
except OSError as err:
    print("OS error: {0}".format(err))
except ValueError:
    print("Could not convert data to an integer.")
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise
finally:
    print("The finally clause is executed whether an exception occurred or not in the preceding code")

Documentation / Reference





Discover More
Card Puncher Data Processing
Python - Name

in Python Names (refer to|are pointer for) objects. Names are introduced by name binding operations such as during the def process. targets that are identifiers if occurring in an assignment,...



Share this page:
Follow us:
Task Runner