Mercurial > cpython-lru_cache-weakref
annotate Lib/exceptions.py @ 10123:bc287c6cfa23 legacy-trunk
Restructured a bit.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 08 Feb 1999 22:27:18 +0000 |
| parents | 5ad1a35f540c |
| children | 9be2726c9b25 |
| rev | line source |
|---|---|
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1 """Class based built-in exception hierarchy. |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 |
|
9145
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
3 New with Python 1.5, all standard built-in exceptions are now class objects by |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
4 default. This gives Python's exception handling mechanism a more |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
5 object-oriented feel. Traditionally they were string objects. Python will |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
6 fallback to string based exceptions if the interpreter is invoked with the -X |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
7 option, or if some failure occurs during class exception initialization (in |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
8 this case a warning will be printed). |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
9 |
|
9145
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
10 Most existing code should continue to work with class based exceptions. Some |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
11 tricky uses of IOError may break, but the most common uses should work. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 |
|
9145
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
13 Here is a rundown of the class hierarchy. You can change this by editing this |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
14 file, but it isn't recommended. The class names described here are expected |
|
9565
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
15 to be found by the bltinmodule.c file. If you add classes here, you must |
|
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
16 modify bltinmodule.c or the exceptions won't be available in the __builtin__ |
|
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
17 module, nor will they be accessible from C. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
18 |
|
9565
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
19 The classes with a `*' are new since Python 1.5. They are defined as tuples |
|
9145
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
20 containing the derived exceptions when string-based exceptions are used. If |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
21 you define your own class based exceptions, they should be derived from |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
22 Exception. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
23 |
| 6317 | 24 Exception(*) |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
25 | |
| 6317 | 26 +-- StandardError(*) |
| 27 | | |
| 28 +-- SystemExit | |
| 29 +-- KeyboardInterrupt | |
| 30 +-- ImportError | |
|
9145
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
31 +-- EnvironmentError(*) |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
32 | | |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
33 | +-- IOError |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
34 | +-- OSError(*) |
|
e578439b981f
Updated the docstring and class hierarchy diagram
Barry Warsaw <barry@python.org>
parents:
8949
diff
changeset
|
35 | |
| 6317 | 36 +-- EOFError |
| 37 +-- RuntimeError | |
|
9565
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
38 | | |
|
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
39 | +-- NotImplementedError(*) |
|
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
40 | |
| 6317 | 41 +-- NameError |
| 42 +-- AttributeError | |
| 43 +-- SyntaxError | |
| 44 +-- TypeError | |
| 45 +-- AssertionError | |
| 46 +-- LookupError(*) | |
| 47 | | | |
| 48 | +-- IndexError | |
| 49 | +-- KeyError | |
| 50 | | |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
51 +-- ArithmeticError(*) |
| 6317 | 52 | | |
| 53 | +-- OverflowError | |
| 54 | +-- ZeroDivisionError | |
| 55 | +-- FloatingPointError | |
| 56 | | |
| 57 +-- ValueError | |
| 58 +-- SystemError | |
| 59 +-- MemoryError | |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
60 """ |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
61 |
| 6317 | 62 class Exception: |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
63 """Proposed base class for all exceptions.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
64 def __init__(self, *args): |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
65 self.args = args |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
66 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 def __str__(self): |
| 6317 | 68 if not self.args: |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
69 return '' |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
70 elif len(self.args) == 1: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
71 return str(self.args[0]) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
72 else: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
73 return str(self.args) |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
75 def __getitem__(self, i): |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
76 return self.args[i] |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 |
|
6394
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
78 class StandardError(Exception): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
79 """Base class for all standard Python exceptions.""" |
|
6394
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
80 pass |
|
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
81 |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
82 class SyntaxError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
83 """Invalid syntax.""" |
|
6245
15bcec3d3259
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
Guido van Rossum <guido@python.org>
parents:
6195
diff
changeset
|
84 filename = lineno = offset = text = None |
| 6317 | 85 msg = "" |
| 86 def __init__(self, *args): | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
87 self.args = args |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
88 if len(self.args) >= 1: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
89 self.msg = self.args[0] |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
90 if len(self.args) == 2: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
91 info = self.args[1] |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
92 try: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
93 self.filename, self.lineno, self.offset, self.text = info |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
94 except: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
95 pass |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 def __str__(self): |
|
6245
15bcec3d3259
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
Guido van Rossum <guido@python.org>
parents:
6195
diff
changeset
|
97 return str(self.msg) |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
99 class EnvironmentError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
100 """Base class for I/O related errors.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
101 def __init__(self, *args): |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
102 self.args = args |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 self.errno = None |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 self.strerror = None |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
105 self.filename = None |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
106 if len(args) == 3: |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
107 # open() errors give third argument which is the filename. BUT, |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
108 # so common in-place unpacking doesn't break, e.g.: |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
109 # |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
110 # except IOError, (errno, strerror): |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
111 # |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
112 # we hack args so that it only contains two items. This also |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
113 # means we need our own __str__() which prints out the filename |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
114 # when it was supplied. |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
115 self.errno, self.strerror, self.filename = args |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
116 self.args = args[0:2] |
| 6317 | 117 if len(args) == 2: |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
118 # common case: PyErr_SetFromErrno() |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
119 self.errno, self.strerror = args |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
120 |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
121 def __str__(self): |
|
8949
0a6892b1a4ac
Use repr() on the filename in EnvironmentError.__str__(). This
Guido van Rossum <guido@python.org>
parents:
8774
diff
changeset
|
122 if self.filename is not None: |
|
8774
edbf631fb7e9
fix __str__ method of EnvironmentError (base class of IOError): was
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
8705
diff
changeset
|
123 return '[Errno %s] %s: %s' % (self.errno, self.strerror, |
|
8949
0a6892b1a4ac
Use repr() on the filename in EnvironmentError.__str__(). This
Guido van Rossum <guido@python.org>
parents:
8774
diff
changeset
|
124 repr(self.filename)) |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
125 elif self.errno and self.strerror: |
|
8774
edbf631fb7e9
fix __str__ method of EnvironmentError (base class of IOError): was
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
8705
diff
changeset
|
126 return '[Errno %s] %s' % (self.errno, self.strerror) |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
127 else: |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
128 return StandardError.__str__(self) |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
129 |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
130 class IOError(EnvironmentError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
131 """I/O operation failed.""" |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
132 pass |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
133 |
|
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
134 class OSError(EnvironmentError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
135 """OS system call failed.""" |
|
8705
8571c1246f09
Added support for including the filename in IOErrors and OSErrors that
Barry Warsaw <barry@python.org>
parents:
7755
diff
changeset
|
136 pass |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
137 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
138 class RuntimeError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
139 """Unspecified run-time error.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
140 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 |
|
9565
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
142 class NotImplementedError(RuntimeError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
143 """Method or function hasn't been implemented yet.""" |
|
9565
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
144 pass |
|
a091185ccfb6
Added NotImplementedError, subclassed from RuntimeError
Barry Warsaw <barry@python.org>
parents:
9145
diff
changeset
|
145 |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
146 class SystemError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
147 """Internal error in the Python interpreter. |
|
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
148 |
|
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
149 Please report this to the Python maintainer, along with the traceback, |
|
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
150 the Python version, and the hardware/OS platform and version.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
151 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
152 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
153 class EOFError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
154 """Read beyond end of file.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
155 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
156 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
157 class ImportError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
158 """Import can't find module, or can't find name in module.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
159 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
160 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
161 class TypeError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
162 """Inappropriate argument type.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
163 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
164 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
165 class ValueError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
166 """Inappropriate argument value (of correct type).""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
167 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
168 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
169 class KeyboardInterrupt(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
170 """Program interrupted by user.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
171 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
172 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
173 class AssertionError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
174 """Assertion failed.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
175 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
176 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
177 class ArithmeticError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
178 """Base class for arithmetic errors.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
179 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
180 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
181 class OverflowError(ArithmeticError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
182 """Result too large to be represented.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
183 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
184 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
185 class FloatingPointError(ArithmeticError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
186 """Floating point operation failed.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
187 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
188 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
189 class ZeroDivisionError(ArithmeticError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
190 """Second argument to a division or modulo operation was zero.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
191 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
192 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
193 class LookupError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
194 """Base class for lookup errors.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
195 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
196 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
197 class IndexError(LookupError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
198 """Sequence index out of range.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
199 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
200 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
201 class KeyError(LookupError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
202 """Mapping key not found.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
203 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
204 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
205 class AttributeError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
206 """Attribute not found.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
207 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
208 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
209 class NameError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
210 """Name not found locally or globally.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
212 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
213 class MemoryError(StandardError): |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
214 """Out of memory.""" |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
215 pass |
| 6317 | 216 |
| 217 class SystemExit(Exception): | |
|
9899
5ad1a35f540c
Added doc strings to the exception classes.
Guido van Rossum <guido@python.org>
parents:
9565
diff
changeset
|
218 """Request to exit from the interpreter.""" |
| 6317 | 219 def __init__(self, *args): |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6394
diff
changeset
|
220 self.args = args |
| 6317 | 221 if len(args) == 0: |
| 222 self.code = None | |
| 223 elif len(args) == 1: | |
| 224 self.code = args[0] | |
| 225 else: | |
| 226 self.code = args |
