Re: Unusual Exception Behaviour

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mk

    Re: Unusual Exception Behaviour

    Robert Rawlins wrote:
    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?
    Sure.

    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:



    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
    >>def anindextoofar(a list):
    print alist[10]

    >>shortlist=ran ge(1,10)
    >>>
    >>try:
    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




Working...