"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
> Rick Wotnaz wrote. > >> ... which leads me to belive that 'msg' is not type(str). It >> can be coerced (str(msg).find works as expected). But what >> exactly is msg? It appears to be of <type 'instance'>, and does >> not test equal to a string. > > it's an instance of the exception type, of course. > >::: > > if you do > > raise SomeError, value > > Python will actually do > > raise SomeError(value) > > (that is, create a SomeError exception and pass the value as its > first argument). > > you can use either form in your code (I prefer the latter > myself). > >::: > > as for catching the exceptions, if you do > > try: > ... > except SomeError, v: > ... > > Python will treat this as > > try: > ... > except: > # some exception occurred > typ = sys.exc_type > exc = sys.exc_value > if issubclass(typ, SomeError): > v = exc > ... > else: > raise # propagate! > > (where typ and exc are internal variables) > Thank you (and Roy Smith) for helping to clarify this. I see that my mental image of an Exception (which, I admit, was not based on extensive R'ing of TFM) was way off. Judging by Steven D'Aprano's code sample, I'm not the only one who was mistaken about the nature of v in your example. I'd always assumed it was the human- readable string associated with the TypeError. Wrong, I see. -- rzed -- http://mail.python.org/mailman/listinfo/python-list