Exceptions

Jp Calderone exarkun at intarweb.us
Mon Feb 3 19:51:28 EST 2003


On Mon, Feb 03, 2003 at 08:34:08PM +0000, Tetsuo wrote:
> 
> So I create functions as methods of a class, then try them?

  Nope.  Create classes as subclasses of Exception, then raise them.

> I'll try it out when I get home some day... But I'll guess now.
> 

class CorruptHardDiskError(Exception):
    pass

def Pythagoras(a,b):
    raise CorruptHardDiskError, "Pythagoras is out"

> try:
>     Pythagoras(18, "x")
> except CorruptHardDiskError:
>     print "Wow"
> 

  Jp

-- 
Seduced, shaggy Samson snored.
She scissored short.  Sorely shorn,
Soon shackled slave, Samson sighed,
Silently scheming,
Sightlessly seeking
Some savage, spectacular suicide.
                -- Stanislaw Lem, "Cyberiad"
-- 
 up 50 days, 3:50, 3 users, load average: 0.09, 0.10, 0.04
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030203/0c9740c1/attachment.sig>


More information about the Python-list mailing list