Recommended exception method for modules?

Grant Edwards ge at nowhere.none
Thu Oct 5 12:25:46 EDT 2000


In article <rf1D5.214$Y32.14283 at newsb.telia.net>, Fredrik Lundh wrote:

>For simple cases, reuse an existing exception (if reasonable),
>or use a single exception class, either inherited from
>Exception or from a suitable standard exception class
>(alternative 2).

I decide that my baud rate example is going to be a ValueError.
My tests and  section 6.8 of the language reference seem to
show that the following two statements are identical

   raise ValueError, 'invalid baud rate: '+str(rate)
   raise ValueError('invalid baud rate: '+str(rate))

Is there any reason to use one form over the other?  

The former seems to be the traditional usage (presumably
because it worked when ValueError was a string), while in the
latter it's a bit more obvious that a class is being
instantiated.

-- 
Grant Edwards                   grante             Yow!  I wish I was a
                                  at               sex-starved manicurist
                               visi.com            found dead in the Bronx!!



More information about the Python-list mailing list