Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Built-in Exceptions} |
Fred Drake | 3bd9ab0 | 1998-07-23 19:33:08 +0000 | [diff] [blame] | 2 | \declaremodule{standard}{exceptions} |
| 3 | |
| 4 | \modulesynopsis{Standard exceptions classes.} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 5 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 7 | Exceptions can be class objects or string objects. While |
| 8 | traditionally, most exceptions have been string objects, in Python |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 9 | 1.5, all standard exceptions have been converted to class objects, |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 10 | and users are encouraged to do the same. The source code for those |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 11 | exceptions is present in the standard library module |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 12 | \module{exceptions}; this module never needs to be imported explicitly. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 14 | For backward compatibility, when Python is invoked with the \code{-X} |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 15 | option, most of the standard exceptions are strings\footnote{For |
Fred Drake | c457ca7 | 1998-07-23 20:31:53 +0000 | [diff] [blame] | 16 | forward-compatibility the new exceptions \exception{LookupError}, |
| 17 | \exception{ArithmeticError}, \exception{EnvironmentError}, and |
| 18 | \exception{StandardError} are tuples.}. This option may be used to |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 19 | run code that breaks because of the different semantics of class based |
| 20 | exceptions. The \code{-X} option will become obsolete in future |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 21 | Python versions, so the recommended solution is to fix the code. |
| 22 | |
| 23 | Two distinct string objects with the same value are considered different |
| 24 | exceptions. This is done to force programmers to use exception names |
| 25 | rather than their string value when specifying exception handlers. |
| 26 | The string value of all built-in exceptions is their name, but this is |
| 27 | not a requirement for user-defined exceptions or exceptions defined by |
| 28 | library modules. |
| 29 | |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 30 | For class exceptions, in a \keyword{try} statement with an \keyword{except} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 31 | clause that mentions a particular class, that clause also handles |
| 32 | any exception classes derived from that class (but not exception |
| 33 | classes from which \emph{it} is derived). Two exception classes |
| 34 | that are not related via subclassing are never equivalent, even if |
| 35 | they have the same name. |
| 36 | \stindex{try} |
| 37 | \stindex{except} |
| 38 | |
| 39 | The built-in exceptions listed below can be generated by the |
| 40 | interpreter or built-in functions. Except where mentioned, they have |
| 41 | an ``associated value'' indicating the detailed cause of the error. |
| 42 | This may be a string or a tuple containing several items of |
| 43 | information (e.g., an error code and a string explaining the code). |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 44 | The associated value is the second argument to the \keyword{raise} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 45 | statement. For string exceptions, the associated value itself will be |
| 46 | stored in the variable named as the second argument of the |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 47 | \keyword{except} clause (if any). For class exceptions, that variable |
| 48 | receives the exception instance. If the exception class is derived |
| 49 | from the standard root class \exception{Exception}, the associated |
| 50 | value is present as the exception instance's \member{args} attribute, |
| 51 | and possibly on other attributes as well. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 52 | \stindex{raise} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 53 | |
| 54 | User code can raise built-in exceptions. This can be used to test an |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 55 | exception handler or to report an error condition ``just like'' the |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 56 | situation in which the interpreter raises the same exception; but |
| 57 | beware that there is nothing to prevent user code from raising an |
| 58 | inappropriate error. |
| 59 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 60 | \setindexsubitem{(built-in exception base class)} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 61 | |
| 62 | The following exceptions are only used as base classes for other |
| 63 | exceptions. When string-based standard exceptions are used, they |
| 64 | are tuples containing the directly derived classes. |
| 65 | |
| 66 | \begin{excdesc}{Exception} |
| 67 | The root class for exceptions. All built-in exceptions are derived |
| 68 | from this class. All user-defined exceptions should also be derived |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 69 | from this class, but this is not (yet) enforced. The \function{str()} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 70 | function, when applied to an instance of this class (or most derived |
| 71 | classes) returns the string value of the argument or arguments, or an |
Guido van Rossum | 6cd7ecb | 1997-10-07 14:41:04 +0000 | [diff] [blame] | 72 | empty string if no arguments were given to the constructor. When used |
| 73 | as a sequence, this accesses the arguments given to the constructor |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 74 | (handy for backward compatibility with old code). The arguments are |
Fred Drake | c457ca7 | 1998-07-23 20:31:53 +0000 | [diff] [blame] | 75 | also available on the instance's \member{args} attribute, as a tuple. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 76 | \end{excdesc} |
| 77 | |
| 78 | \begin{excdesc}{StandardError} |
| 79 | The base class for built-in exceptions. All built-in exceptions are |
| 80 | derived from this class, which is itself derived from the root class |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 81 | \exception{Exception}. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 82 | \end{excdesc} |
| 83 | |
| 84 | \begin{excdesc}{ArithmeticError} |
| 85 | The base class for those built-in exceptions that are raised for |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 86 | various arithmetic errors: \exception{OverflowError}, |
| 87 | \exception{ZeroDivisionError}, \exception{FloatingPointError}. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 88 | \end{excdesc} |
| 89 | |
| 90 | \begin{excdesc}{LookupError} |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 91 | The base class for the exceptions that are raised when a key or |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 92 | index used on a mapping or sequence is invalid: \exception{IndexError}, |
| 93 | \exception{KeyError}. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 94 | \end{excdesc} |
| 95 | |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 96 | \begin{excdesc}{EnvironmentError} |
| 97 | The base class for exceptions that |
| 98 | can occur outside the Python system: \exception{IOError}, |
| 99 | \exception{OSError}. When exceptions of this type are created with a |
| 100 | 2-tuple, the first item is available on the instance's \member{errno} |
| 101 | attribute (it is assumed to be an error number), and the second item |
| 102 | is available on the \member{strerror} attribute (it is usually the |
| 103 | associated error message). The tuple itself is also available on the |
| 104 | \member{args} attribute. |
| 105 | |
| 106 | When an \exception{EnvironmentError} exception is instantiated with a |
| 107 | 3-tuple, the first two items are available as above, while the third |
| 108 | item is available on the \member{filename} attribute. However, for |
| 109 | backwards compatibility, the \member{args} attribute contains only a |
| 110 | 2-tuple of the first two constructor arguments. |
| 111 | |
| 112 | The \member{filename} attribute is \code{None} when this exception is |
| 113 | created with other than 3 arguments. The \member{errno} and |
| 114 | \member{strerror} attributes are also \code{None} when the instance was |
| 115 | created with other than 2 or 3 arguments. In this last case, |
| 116 | \member{args} contains the verbatim constructor arguments as a tuple. |
| 117 | \end{excdesc} |
| 118 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 119 | \setindexsubitem{(built-in exception)} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 120 | |
| 121 | The following exceptions are the exceptions that are actually raised. |
| 122 | They are class objects, except when the \code{-X} option is used to |
| 123 | revert back to string-based standard exceptions. |
| 124 | |
| 125 | \begin{excdesc}{AssertionError} |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 126 | Raised when an \keyword{assert} statement fails. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 127 | \stindex{assert} |
| 128 | \end{excdesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 129 | |
| 130 | \begin{excdesc}{AttributeError} |
| 131 | % xref to attribute reference? |
| 132 | Raised when an attribute reference or assignment fails. (When an |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 133 | object does not support attribute references or attribute assignments |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 134 | at all, \exception{TypeError} is raised.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 135 | \end{excdesc} |
| 136 | |
| 137 | \begin{excdesc}{EOFError} |
| 138 | % XXXJH xrefs here |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 139 | Raised when one of the built-in functions (\function{input()} or |
| 140 | \function{raw_input()}) hits an end-of-file condition (\EOF{}) without |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 141 | reading any data. |
| 142 | % XXXJH xrefs here |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 143 | (N.B.: the \method{read()} and \method{readline()} methods of file |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 144 | objects return an empty string when they hit \EOF{}.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 145 | \end{excdesc} |
| 146 | |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 147 | \begin{excdesc}{FloatingPointError} |
| 148 | Raised when a floating point operation fails. This exception is |
| 149 | always defined, but can only be raised when Python is configured with |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 150 | the \code{--with-fpectl} option, or the \constant{WANT_SIGFPE_HANDLER} |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 151 | symbol is defined in the \file{config.h} file. |
| 152 | \end{excdesc} |
| 153 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 154 | \begin{excdesc}{IOError} |
| 155 | % XXXJH xrefs here |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 156 | Raised when an I/O operation (such as a \keyword{print} statement, the |
| 157 | built-in \function{open()} function or a method of a file object) fails |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 158 | for an I/O-related reason, e.g., ``file not found'' or ``disk full''. |
| 159 | |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 160 | This class is derived \exception{EnvironmentError}. See the discussion |
| 161 | above for more information on exception instance attributes. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 162 | \end{excdesc} |
| 163 | |
| 164 | \begin{excdesc}{ImportError} |
| 165 | % XXXJH xref to import statement? |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 166 | Raised when an \keyword{import} statement fails to find the module |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 167 | definition or when a \code{from {\rm \ldots} import} fails to find a |
| 168 | name that is to be imported. |
| 169 | \end{excdesc} |
| 170 | |
| 171 | \begin{excdesc}{IndexError} |
| 172 | % XXXJH xref to sequences |
| 173 | Raised when a sequence subscript is out of range. (Slice indices are |
| 174 | silently truncated to fall in the allowed range; if an index is not a |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 175 | plain integer, \exception{TypeError} is raised.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 176 | \end{excdesc} |
| 177 | |
| 178 | \begin{excdesc}{KeyError} |
| 179 | % XXXJH xref to mapping objects? |
| 180 | Raised when a mapping (dictionary) key is not found in the set of |
| 181 | existing keys. |
| 182 | \end{excdesc} |
| 183 | |
| 184 | \begin{excdesc}{KeyboardInterrupt} |
| 185 | Raised when the user hits the interrupt key (normally |
Fred Drake | 2a1cc3e | 1998-04-28 13:38:54 +0000 | [diff] [blame] | 186 | \kbd{Control-C} or \kbd{DEL}). During execution, a check for |
| 187 | interrupts is made regularly. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 188 | % XXXJH xrefs here |
Fred Drake | 2a1cc3e | 1998-04-28 13:38:54 +0000 | [diff] [blame] | 189 | Interrupts typed when a built-in function \function{input()} or |
| 190 | \function{raw_input()}) is waiting for input also raise this |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 191 | exception. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 192 | \end{excdesc} |
| 193 | |
| 194 | \begin{excdesc}{MemoryError} |
| 195 | Raised when an operation runs out of memory but the situation may |
| 196 | still be rescued (by deleting some objects). The associated value is |
| 197 | a string indicating what kind of (internal) operation ran out of memory. |
| 198 | Note that because of the underlying memory management architecture |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 199 | (\C{}'s \cfunction{malloc()} function), the interpreter may not |
| 200 | always be able to completely recover from this situation; it |
| 201 | nevertheless raises an exception so that a stack traceback can be |
| 202 | printed, in case a run-away program was the cause. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 203 | \end{excdesc} |
| 204 | |
| 205 | \begin{excdesc}{NameError} |
| 206 | Raised when a local or global name is not found. This applies only |
| 207 | to unqualified names. The associated value is the name that could |
| 208 | not be found. |
| 209 | \end{excdesc} |
| 210 | |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 211 | \begin{excdesc}{OSError} |
| 212 | %xref for os module |
Fred Drake | c457ca7 | 1998-07-23 20:31:53 +0000 | [diff] [blame] | 213 | This class is derived from \exception{EnvironmentError} and is used |
| 214 | primarily as the by the \module{os} module's \code{os.error} |
| 215 | exception. See \exception{EnvironmentError} above for a description |
Barry Warsaw | da00c87 | 1998-07-23 19:57:35 +0000 | [diff] [blame] | 216 | of the possible associated values. |
| 217 | \end{excdesc} |
| 218 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 219 | \begin{excdesc}{OverflowError} |
| 220 | % XXXJH reference to long's and/or int's? |
| 221 | Raised when the result of an arithmetic operation is too large to be |
| 222 | represented. This cannot occur for long integers (which would rather |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 223 | raise \exception{MemoryError} than give up). Because of the lack of |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 224 | standardization of floating point exception handling in \C{}, most |
| 225 | floating point operations also aren't checked. For plain integers, |
| 226 | all operations that can overflow are checked except left shift, where |
| 227 | typical applications prefer to drop bits than raise an exception. |
| 228 | \end{excdesc} |
| 229 | |
| 230 | \begin{excdesc}{RuntimeError} |
| 231 | Raised when an error is detected that doesn't fall in any of the |
| 232 | other categories. The associated value is a string indicating what |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 233 | precisely went wrong. (This exception is mostly a relic from a |
| 234 | previous version of the interpreter; it is not used very much any |
| 235 | more.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 236 | \end{excdesc} |
| 237 | |
| 238 | \begin{excdesc}{SyntaxError} |
| 239 | % XXXJH xref to these functions? |
| 240 | Raised when the parser encounters a syntax error. This may occur in |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 241 | an \keyword{import} statement, in an \keyword{exec} statement, in a call |
| 242 | to the built-in function \function{eval()} or \function{input()}, or |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 243 | when reading the initial script or standard input (also |
| 244 | interactively). |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 245 | |
| 246 | When class exceptions are used, instances of this class have |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 247 | atttributes \member{filename}, \member{lineno}, \member{offset} and |
| 248 | \member{text} for easier access to the details; for string exceptions, |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 249 | the associated value is usually a tuple of the form |
| 250 | \code{(message, (filename, lineno, offset, text))}. |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 251 | For class exceptions, \function{str()} returns only the message. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 252 | \end{excdesc} |
| 253 | |
| 254 | \begin{excdesc}{SystemError} |
| 255 | Raised when the interpreter finds an internal error, but the |
| 256 | situation does not look so serious to cause it to abandon all hope. |
| 257 | The associated value is a string indicating what went wrong (in |
| 258 | low-level terms). |
| 259 | |
| 260 | You should report this to the author or maintainer of your Python |
| 261 | interpreter. Be sure to report the version string of the Python |
| 262 | interpreter (\code{sys.version}; it is also printed at the start of an |
| 263 | interactive Python session), the exact error message (the exception's |
| 264 | associated value) and if possible the source of the program that |
| 265 | triggered the error. |
| 266 | \end{excdesc} |
| 267 | |
| 268 | \begin{excdesc}{SystemExit} |
| 269 | % XXXJH xref to module sys? |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 270 | This exception is raised by the \function{sys.exit()} function. When it |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 271 | is not handled, the Python interpreter exits; no stack traceback is |
| 272 | printed. If the associated value is a plain integer, it specifies the |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 273 | system exit status (passed to \C{}'s \cfunction{exit()} function); if it is |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 274 | \code{None}, the exit status is zero; if it has another type (such as |
| 275 | a string), the object's value is printed and the exit status is one. |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 276 | |
| 277 | When class exceptions are used, the instance has an attribute |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 278 | \member{code} which is set to the proposed exit status or error message |
Guido van Rossum | df3dba0 | 1997-10-05 18:51:26 +0000 | [diff] [blame] | 279 | (defaulting to \code{None}). |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 280 | |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 281 | A call to \function{sys.exit()} is translated into an exception so that |
| 282 | clean-up handlers (\keyword{finally} clauses of \keyword{try} statements) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 283 | can be executed, and so that a debugger can execute a script without |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 284 | running the risk of losing control. The \function{os._exit()} function |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 285 | can be used if it is absolutely positively necessary to exit |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 286 | immediately (e.g., after a \function{fork()} in the child process). |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 287 | \end{excdesc} |
| 288 | |
| 289 | \begin{excdesc}{TypeError} |
| 290 | Raised when a built-in operation or function is applied to an object |
| 291 | of inappropriate type. The associated value is a string giving |
| 292 | details about the type mismatch. |
| 293 | \end{excdesc} |
| 294 | |
| 295 | \begin{excdesc}{ValueError} |
| 296 | Raised when a built-in operation or function receives an argument |
| 297 | that has the right type but an inappropriate value, and the |
| 298 | situation is not described by a more precise exception such as |
Fred Drake | 27467e4 | 1998-07-23 19:47:41 +0000 | [diff] [blame] | 299 | \exception{IndexError}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 300 | \end{excdesc} |
| 301 | |
| 302 | \begin{excdesc}{ZeroDivisionError} |
| 303 | Raised when the second argument of a division or modulo operation is |
| 304 | zero. The associated value is a string indicating the type of the |
| 305 | operands and the operation. |
| 306 | \end{excdesc} |