[Tutor] Checking for custom error codes

Bob Gailer bgailer at alum.rpi.edu
Tue Aug 7 17:40:01 CEST 2007


wormwood_3 wrote:
> Hi all,
>
> I am new to Python programming and this list, looks like a great place so far!
>
> Recently I was trying to do a "try: X except Y: Z" statement, checking for a custom error code that the rwhois.py module throws. Some details on the exercise and the full code can be found on this post ( http://assistedsilicon.blogspot.com/2007/08/fun-with-python-domainspotter.html ). So, here is what I tried:
>
>         for potdomain in self.potdomains:
>             try: 
>                 who.whois(potdomain)
>                 self.availdomains.append(potdomain)
>             except 'NoSuchDomain':
>                 pass
>             self.totalchecked+=1
>
> If you need more context, the whole program is here ( http://assistedsilicon.blogspot.com/2007/08/fun-with-python-domainspotter.html#code ). I first tried simply "except NoSuchDomain", since that was what I saw rwhois throw when I sent it a domain that was not registered. That did not work, so I quoted it. I got a warning that throwing a string exception is deprecated, but the check did not work anyway. Am I trying to check for this custom error wrongly? How should it be done?
>   
Examining rwhois.py reveals

raise 'NoSuchDomain'

which is a string exception. Which should work even tho deprecated.

When you say it did not work what is the evidence?
>
>   


-- 
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC




More information about the Tutor mailing list