I certainly like that implementation for logging the exceptions, however, atSure.
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.Remember, Google is your friend, here's the crux of the method without
the fancy schmancy sugar coating:
http://linux.byexamples.com/archives...into-log-file/
if __name__=="__main__":
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
print alist[10]>>def anindextoofar(alist):
anindextoofar(shortlist)>>shortlist=range(1,10)
try:
except IndexError, err:
print err
traceback.print_exc(file=sys.stdout)
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