Robert Rawlins wrote:
Sure.
I'm a little confused as to how I can modify that
Remember, Google is your friend, here's the crux of the method without
the fancy schmancy sugar coating:
if __name__=="__ma in__":
try:
main()
except:
print "Trigger Exception, traceback info forward to log file."
traceback.print _exc(file=open( "errlog.txt","a "))
sys.exit(1)
This will obviously capture every exception happening in the main()
function.
The drawback of this method is that you cannot capture the error
message / object accompanying the exception, as you normally can do
while capturing specific exception:
print alist[10]
anindextoofar(s hortlist)
except IndexError, err:
print err
traceback.print _exc(file=sys.s tdout)
list index out of range
Traceback (most recent call last):
File "<pyshell#177>" , line 2, in <module>
File "<pyshell#169>" , line 2, in anindextoofar
IndexError: list index out of range
I certainly like that implementation for logging the exceptions, however, at
the moment I don't even know where the exceptions are occurring, or what
type they are, could I still use this method to log any and all exceptions
raised in the application?
the moment I don't even know where the exceptions are occurring, or what
type they are, could I still use this method to log any and all exceptions
raised in the application?
I'm a little confused as to how I can modify that
implementation to do so.
the fancy schmancy sugar coating:
if __name__=="__ma in__":
try:
main()
except:
print "Trigger Exception, traceback info forward to log file."
traceback.print _exc(file=open( "errlog.txt","a "))
sys.exit(1)
This will obviously capture every exception happening in the main()
function.
The drawback of this method is that you cannot capture the error
message / object accompanying the exception, as you normally can do
while capturing specific exception:
>>import sys
>>import traceback
>>import traceback
>>def anindextoofar(a list):
>>shortlist=ran ge(1,10)
>>>
>>try:
>>>
>>try:
except IndexError, err:
print err
traceback.print _exc(file=sys.s tdout)
list index out of range
Traceback (most recent call last):
File "<pyshell#177>" , line 2, in <module>
File "<pyshell#169>" , line 2, in anindextoofar
IndexError: list index out of range