diff options
author | Guido van Rossum <guido@python.org> | 1998-08-12 02:38:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-08-12 02:38:11 (GMT) |
commit | e03c05059534b4783c5631517cb16f79531358e8 (patch) | |
tree | 82285bf56d90ac5c062f328516a959dd416b8e45 /Lib/dos-8x3/exceptio.py | |
parent | 887d072cc04be23e6758257b326499bd1572b929 (diff) | |
download | cpython-e03c05059534b4783c5631517cb16f79531358e8.zip cpython-e03c05059534b4783c5631517cb16f79531358e8.tar.gz cpython-e03c05059534b4783c5631517cb16f79531358e8.tar.bz2 |
The usual.
Diffstat (limited to 'Lib/dos-8x3/exceptio.py')
-rw-r--r-- | Lib/dos-8x3/exceptio.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/Lib/dos-8x3/exceptio.py b/Lib/dos-8x3/exceptio.py index ba63be6..28711df 100644 --- a/Lib/dos-8x3/exceptio.py +++ b/Lib/dos-8x3/exceptio.py @@ -80,15 +80,44 @@ class SyntaxError(StandardError): def __str__(self): return str(self.msg) -class IOError(StandardError): +class EnvironmentError(StandardError): + """Base class for exceptions that occur outside the Python system. + Primarily used as a base class for OSError and IOError.""" def __init__(self, *args): self.args = args self.errno = None self.strerror = None + self.filename = None + if len(args) == 3: + # open() errors give third argument which is the filename. BUT, + # so common in-place unpacking doesn't break, e.g.: + # + # except IOError, (errno, strerror): + # + # we hack args so that it only contains two items. This also + # means we need our own __str__() which prints out the filename + # when it was supplied. + self.errno, self.strerror, self.filename = args + self.args = args[0:2] if len(args) == 2: # common case: PyErr_SetFromErrno() - self.errno = args[0] - self.strerror = args[1] + self.errno, self.strerror = args + + def __str__(self): + if self.filename is not None: + return '[Errno %s] %s: %s' % (self.errno, self.strerror, + repr(self.filename)) + elif self.errno and self.strerror: + return '[Errno %s] %s' % (self.errno, self.strerror) + else: + return StandardError.__str__(self) + +class IOError(EnvironmentError): + pass + +class OSError(EnvironmentError): + """Used by the posix module.""" + pass class RuntimeError(StandardError): pass |