Catch several exceptions : Catch Exceptions « Language Basics « Python






Catch several exceptions

Catch several exceptions
class MyError: pass

def oops():
    raise MyError()

def doomed():
    try:
        oops()
    except IndexError:
        print 'caught an index error!'
    except MyError, data:
        print 'caught error:', MyError, data
    else:
        print 'no error caught...'

if __name__ == '__main__':
    doomed()


           
       








Related examples in the same category

1.Catch exception throwed inside a functionCatch exception throwed inside a function
2.Catch and recover exceptionCatch and recover exception