# Following class in ldtp.py file class LdtpExecutionError (Exception): def __init__(self, value): self.value = value def __str__(self): return repr (self.value) # test1.py file import ldtp try: execfile ('test2.py') except ldtp.LdtpExecutionError, msg: print msg