import sys

try:
    0/0
except:
    a,b,c=sys.exc_info()
    print('Error name: %s' % a.__name__)
    print('Message: %s' % b.message)
    print('Error in line: %s' % c.tb_lineno)    

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.