[Dev] Re: raise problem
Phillip J. Eby
pje at telecommunity.com
Thu Feb 17 20:06:04 PST 2005
At 07:37 PM 2/17/05 -0800, Morgen Sagen wrote:
>raise takes 3 arguments:
>http://www.python.org/doc/current/ref/raise.html#raise
More precisely, it takes anywhere from zero to three arguments:
raise: reraise last exception
raise typ_or_val: a string, a type of exception to raise, or an instance of
an exception
raise typ,val: assuming isinstance(excvalue,exctype), raises excvalue
raise typ,val,tb: like the two argument form, but with an explicit
traceback, that changes what will be shown as the stack trace. This form
is mainly used when error handling code saves one error, and wants to be
able to revert to handling that error later even though it may handle other
errors in the interim.
Anyway, the specific code in question should just use zero-argument raise,
unless there's some reason that clients of ClassLoader want all exceptions
to be transformed into ImportError, in which case the correct form would be
this rather ugly three-argument form:
raise ImportError, ImportError(sys.exc_info()[1]), sys.exc_info()[2]
This is basically wrapping the original exception instance (exc_info()[1])
in an ImportError, and reusing the traceback. I'm using sys.exc_info()
instead of sys.exc_value and exc_traceback because those variables are not
threadsafe nor frame-specific, as exc_info() is. (See
http://www.python.org/doc/current/lib/module-sys.html for details.)
Anyway, either the zero argument or three argument form is needed in order
to address John's issue; the one or two argument forms won't work.
>On Feb 17, 2005, at 5:46 PM, Andi Vajda wrote:
>
>>
>>The reason I changed this is because it was incorrect python before. The
>>raise statement takes only two arguments, an exception class and one
>>value or tuple of values.
>>
>>http://www.python.org/doc/current/lib/module-exceptions.html#l2h-280
>>
>>Andi..
>>
>>On Thu, 17 Feb 2005, John Anderson wrote:
>>
>>>Hi Morgen:
>>>
>>>I just ran into the same problem you did, where a syntax error in parcel
>>>loading didn't send me off the the right place when debugging under Wing.
>>>
>>>I'm not sure I completely understand it yet, however, it looks like
>>>Andi's recent change in ClassLoader.py
>>>
>>> raise ImportError, sys.exc_value, sys.exc_traceback
>>>
>>>to
>>>
>>> raise ImportError, (sys.exc_value, sys.exc_traceback)
>>>
>>>is the cause.
>>>
>>>John
>>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>>
>>Open Source Applications Foundation "Dev" mailing list
>>http://lists.osafoundation.org/mailman/listinfo/dev
>
>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>Open Source Applications Foundation "Dev" mailing list
>http://lists.osafoundation.org/mailman/listinfo/dev
More information about the Dev
mailing list