Which exception to use?

Erik Max Francis max at alcyone.com
Wed Jan 29 01:25:42 CET 2003

Chad Netzer wrote:

> I agree.  When raising a class, an instance is eventually created (by
> the interpreter).  I just meant that the user doesn't create it
> directly.  I haven't discerned which is more advantageous.  I guess it
> is (largely) a matter of personal style.

Presuming the exception is of the form
ExceptionSubclass(stringDescription), I prefer the format

	raise ExceptionSubclass, stringDescription

If you're doing extra fancy things and have overridden the exception
class to take a non-standard constructor, then I prefer the explcit form
of raising an instance:

	raise SomeOtherClass(errorCode, details, sequenceOfInfo)

 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Patriotism is the last refuge of a scoundrel.
\__/ Samuel Johnson
    Kepler's laws / http://www.alcyone.com/max/physics/kepler/
 A proof of Kepler's laws.

More information about the Python-list mailing list