secynic / ipwhois

Retrieve and parse whois data for IPv4 and IPv6 addresses
https://ipwhois.readthedocs.io/en/latest
BSD 2-Clause "Simplified" License
555 stars 121 forks source link

All errors use Exception as a base class, preventing succinct error handling #213

Closed frankwoodall closed 6 years ago

frankwoodall commented 6 years ago

Problem

Because all of your exceptions inherit directly from the Exception class, it's impossible to write a small exception handler for your library. As it stands, I'm forced to either handle each exception explicitly or catch Exception directly -- both of which are undesirable.

I suggest something like this:


class IPWhoisException(Exception):
    pass

class NetError(IPWhoisException):
    """
    An Exception for when a parameter provided is not an instance of
    ipwhois.net.Net.
    """

class IPDefinedError(IPWhoisException):
    """
    An Exception for when the IP is defined (does not need to be resolved).
    """

# ... etc ...

Which would then allow me to do this:


try:
    # ipwhois lookup
except IPWhoisException:
    # handle it

Thanks

secynic commented 6 years ago

This is fixed in the dev branch. See here: https://github.com/secynic/ipwhois/issues/205