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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
20 +-- StandardError(*)
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
21 |
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
22 +-- SystemExit
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
23 +-- KeyboardInterrupt
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
24 +-- ImportError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
25 +-- IOError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
26 +-- EOFError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
27 +-- RuntimeError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
28 +-- NameError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
29 +-- AttributeError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
30 +-- SyntaxError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
31 +-- TypeError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
32 +-- AssertionError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
33 +-- LookupError(*)
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
34 | |
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
35 | +-- IndexError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
36 | +-- KeyError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
37 |
6325
5cdc3ca053d6 NumberError => ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6317
diff changeset
38 +-- ArithmeticError(*)
6317
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
39 | |
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
40 | +-- OverflowError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
41 | +-- ZeroDivisionError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
42 | +-- FloatingPointError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
43 |
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
44 +-- ValueError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
45 +-- SystemError
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
56 elif len(self.args) == 1:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
69 msg = ""
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
70 def __init__(self, *args):
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
71 self.args = args
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
72 if len(self.args) >= 1:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
73 self.msg = self.args[0]
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
74 if len(self.args) == 2:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
75 info = self.args[1]
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
76 try:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
77 self.filename, self.lineno, self.offset, self.text = info
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
78 except:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
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
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
146
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
147 class SystemExit(Exception):
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
148 def __init__(self, *args):
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
149 self.args = args
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
150 if len(args) == 0:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
151 self.code = None
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
152 elif len(args) == 1:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
153 self.code = args[0]
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
154 else:
71b40cc4cc03 Two subtle changes:
Guido van Rossum <guido@python.org>
parents: 6272
diff changeset
155 self.code = args