[Tutor] die or exit function?
doug.shawhan at gmail.com
Wed Jun 14 15:17:18 CEST 2006
Putting a try:/except: loop in your __main__() (or whatever you call
your base function) with sys.exit("Message") is pretty much the way I
always do it.
gak = puke + die
If you would like sys.exit() to provide you with a bit more
information (like what actually happened during the failure and
where!) I found this handy function:
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
excArgs = exc.__dict__["args"]
excArgs = "<no args>"
excArgsString = ''
for item in excArgs:
excArgsString = excArgsString + ' ' + str(item)
excTb = traceback.format_tb(trbk, maxTBlevel)
excTbString = ''
for item in excTb:
excTbString = excTbString + " " + str(item)
report = "%s %s %s"%(excName, excArgsString, excTbString)
This function now goes in most of what I do that requires error reporting.
Hope this helps!
On 6/13/06, Andy Koch <andy.koch at pc-doctor.com> wrote:
> Bkgd: I've been doing PHP for the last several years.
> Q: In PHP there are functions die and exit which terminate processing of
> a script with an optional string output. Is there something similar to
> this in Python?
> Tutor maillist - Tutor at python.org
More information about the Tutor