What Exceptions are there? (was: "a better input")

Steve Holden sholden at holdenweb.com
Fri May 10 11:01:15 EDT 2002


"Emile van Sebille" <emile at fenx.com> wrote ...
> Louis M. Pecora
> > Ok, you knew there was an exception of that type (ValueError), but is
> > there a way to get a list of exceptions in a Python module or in the
> > main Python core?  There are probably zillions.
>
>  dir(__builtins__) gives you a good start.
>

But, unfortunately, if you mean "what exceptions a particular piece of code
might raise" then the answer is a plain "no". Unlike Java, which pretty much
insists that you have to either handle exceptions that your code might throw
or declare that you yourself throw them, Python takes a very relaxed
attitude to all this.

There is a PEP which specifies interfaces, and possible exception conditions
may be part of that (it's too long ago since I read it), but until that
becomes reality it's unlikely things will go any farther.

You'll also get a better idea of the *standard* exceptions with

>>> import exceptions
>>> dir(exceptions)
['ArithmeticError', 'AssertionError', 'AttributeError',
'DeprecationWarning', 'EOFError', 'EnvironmentError', 'Exception',
'FloatingPointError', 'IOError', 'ImportError', 'IndentationError',
'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError',
'NameError', 'NotImplementedError', 'OSError', 'OverflowError',
'OverflowWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning',
'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning',
'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError',
'UnicodeError', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError',
'__doc__', '__name_
_']

Most module authors now declare their own exceptions to be a subclass of
exceptions.Exception, but some legacy code is still using *string*
exceptions, and there is no requirement that programmer-defined exceptions
must subclass the main Exception class.

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list