Mercurial > cpython-lru_cache-weakref
annotate Lib/exceptions.py @ 6719:faebc1940432 legacy-trunk
Understand -Xlinker option.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 02 Dec 1997 20:38:11 +0000 |
| parents | 784a16f56643 |
| children | fb4b4d069cc7 |
| 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 |
|
6272
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
3 This is a new feature whereby all the standard built-in exceptions, |
|
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
4 traditionally string objects, are replaced with classes. This gives |
|
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
5 Python's exception handling mechanism a more object-oriented feel. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
7 Most existing code should continue to work with class based |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 exceptions. Some tricky uses of IOError may break, but the most |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
9 common uses should work. |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 |
|
6272
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
11 To disable this feature, start the Python executable with the -X option. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 Here is a rundown of the class hierarchy. You can change this by |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 editing this file, but it isn't recommended. The classes with a `*' |
|
6272
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
15 are new with this feature. They are defined as tuples containing the |
|
775899583da6
#Adapt the doc string to reality.
Guido van Rossum <guido@python.org>
parents:
6245
diff
changeset
|
16 derived exceptions when string-based exceptions are used. |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 |
| 6317 | 18 Exception(*) |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 | |
| 6317 | 20 +-- StandardError(*) |
| 21 | | |
| 22 +-- SystemExit | |
| 23 +-- KeyboardInterrupt | |
| 24 +-- ImportError | |
| 25 +-- IOError | |
| 26 +-- EOFError | |
| 27 +-- RuntimeError | |
| 28 +-- NameError | |
| 29 +-- AttributeError | |
| 30 +-- SyntaxError | |
| 31 +-- TypeError | |
| 32 +-- AssertionError | |
| 33 +-- LookupError(*) | |
| 34 | | | |
| 35 | +-- IndexError | |
| 36 | +-- KeyError | |
| 37 | | |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
38 +-- ArithmeticError(*) |
| 6317 | 39 | | |
| 40 | +-- OverflowError | |
| 41 | +-- ZeroDivisionError | |
| 42 | +-- FloatingPointError | |
| 43 | | |
| 44 +-- ValueError | |
| 45 +-- SystemError | |
| 46 +-- MemoryError | |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 """ |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
48 |
| 6317 | 49 class Exception: |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 def __init__(self, *args): |
| 6317 | 51 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
|
52 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
53 def __str__(self): |
| 6317 | 54 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
|
55 return '' |
| 6317 | 56 elif len(self.args) == 1: |
| 57 return str(self.args[0]) | |
|
6245
15bcec3d3259
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
Guido van Rossum <guido@python.org>
parents:
6195
diff
changeset
|
58 else: |
|
15bcec3d3259
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
Guido van Rossum <guido@python.org>
parents:
6195
diff
changeset
|
59 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
|
60 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
61 def __getitem__(self, i): |
| 6317 | 62 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
|
63 |
|
6394
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
64 class StandardError(Exception): |
|
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
65 pass |
|
784a16f56643
Move the __getitem__() definition from StandardException to Exception.
Fred Drake <fdrake@acm.org>
parents:
6325
diff
changeset
|
66 |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 class SyntaxError(StandardError): |
|
6245
15bcec3d3259
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
Guido van Rossum <guido@python.org>
parents:
6195
diff
changeset
|
68 filename = lineno = offset = text = None |
| 6317 | 69 msg = "" |
| 70 def __init__(self, *args): | |
| 71 self.args = args | |
| 72 if len(self.args) >= 1: | |
| 73 self.msg = self.args[0] | |
| 74 if len(self.args) == 2: | |
| 75 info = self.args[1] | |
| 76 try: | |
| 77 self.filename, self.lineno, self.offset, self.text = info | |
| 78 except: | |
| 79 pass | |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
80 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
|
81 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
|
82 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
83 class IOError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 def __init__(self, *args): |
| 6317 | 85 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
|
86 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
|
87 self.strerror = None |
| 6317 | 88 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
|
89 # common case: PyErr_SetFromErrno() |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
90 self.errno = args[0] |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
91 self.strerror = args[1] |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
92 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
93 class RuntimeError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
94 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
95 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 class SystemError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
97 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
99 class EOFError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
100 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
101 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
102 class ImportError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
105 class TypeError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
106 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
107 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
108 class ValueError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
109 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
110 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 class KeyboardInterrupt(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
112 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
113 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
114 class AssertionError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
115 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
116 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
117 class ArithmeticError(StandardError): |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
118 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
120 class OverflowError(ArithmeticError): |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
121 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
123 class FloatingPointError(ArithmeticError): |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 |
|
6325
5cdc3ca053d6
NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6317
diff
changeset
|
126 class ZeroDivisionError(ArithmeticError): |
|
6195
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
127 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
128 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
129 class LookupError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
132 class IndexError(LookupError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
134 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
135 class KeyError(LookupError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
136 pass |
|
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 AttributeError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
139 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
140 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 class NameError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 pass |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
143 |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 class MemoryError(StandardError): |
|
d97980e7c05f
New file, which is imported by the built-in module when python is
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
145 pass |
| 6317 | 146 |
| 147 class SystemExit(Exception): | |
| 148 def __init__(self, *args): | |
| 149 self.args = args | |
| 150 if len(args) == 0: | |
| 151 self.code = None | |
| 152 elif len(args) == 1: | |
| 153 self.code = args[0] | |
| 154 else: | |
| 155 self.code = args |
