Context Manager getting str instead of AttributeError instance

Discussion in 'Python' started by Prasad, Ramit, Mar 15, 2012.

  1. So I have a context manager used to catch errors

    def __exit__( self, exceptionClass, exception, tracebackObject ):
    if isinstance( exception, self.exceptionClasses ):
    #do something here

    Normally exception would be the exception instance, but for
    AttributeError it seems to be a string instead.

    1) Why is AttributeError different than the other built-ins
    in this respect?
    2) Are there other standard errors like this (I know
    that SystemExit isdifferent as well)?
    3) Taking into account that I want to include subclasses of
    classes listed in self.exceptionClasses, Is there a better check I can use?

    Ramit


    Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
    712 Main Street | Houston, TX 77002
    work phone: 713 - 216 - 5423

    --


    This email is confidential and subject to important disclaimers and
    conditions including on offers for the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
    Prasad, Ramit, Mar 15, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    2
    Views:
    463
    Thomas G. Marshall
    Aug 3, 2003
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    610
    CBFalconer
    Apr 10, 2004
  3. Sullivan WxPyQtKinter

    It is fun.the result of str.lower(str())

    Sullivan WxPyQtKinter, Mar 7, 2006, in forum: Python
    Replies:
    5
    Views:
    321
    Tim Roberts
    Mar 9, 2006
  4. Stefan Ram

    str.equals(null) or str==null ?

    Stefan Ram, Jul 31, 2006, in forum: Java
    Replies:
    21
    Views:
    14,635
    Oliver Wong
    Aug 3, 2006
  5. maestro
    Replies:
    1
    Views:
    290
    Chris
    Aug 11, 2008
Loading...

Share This Page