[Python-Dev] Re: Syntax for "except"
Edward C. Jones
edcjones at erols.com
Tue Feb 10 20:24:21 EST 2004
Here is a weak proposal for a generalized type of exception. Since I
know nothing about either language design or implementation, my hope is
to trigger some thinking by the experts.
I would like to propose a class ExceptionList which is an exception
containing a list, It can be used in two ways. Suppose
MyError = ExceptionList( (ValueError, TypeError) )
"except MyError:"
handles MyError, ValueError, and TypeError or any exception derived from
them. This generalizes the current "except (ValueError, TypeError):".
"raise MyError"
raises an exception that can be handled by any except clause that
handles MyError, ValueError, or TypeError. Here is an example for this:
Suppose I invent the exception LengthError which is raised when a
sequence (including sys.argv) is the wrong length. It is also raised if
a function is passed the wrong number of arguments. I have a lot of code
which raises and/or handles ValueError or TypeError in these situations.
MyError can handle exceptions raised by the legacy code or vice versa.
Perhaps MyError could be a class with base classes ValueError and TypeError.
More information about the Python-Dev
mailing list