Press "Enter" to skip to content

Python Notes 8 : Exception Handling

Exceptions are referred to as run-time errors. While coding in python, we can encounter multiple types of exceptions. Complete list of python exceptions can be found here.

Exceptions which are not fatal for execution of the remaining program can be avoided by using try & except statements 

An example of the try & except code will be as follows –

def askint():
        try:
            val = int(raw_input("Please enter an integer: "))
        except:
            print "Looks like you did not enter an integer!"
            
        finally:
            print "Finally, I executed!"
        print val

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *