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.
Edward C. Jones wrote:
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 don't know anything about it either.
MyError = ExceptionList( (ValueError, TypeError) )
"raise MyError" raises an exception that can be handled by any except clause that handles MyError, ValueError, or TypeError.
Perhaps MyError could be a class with base classes ValueError and TypeError.
So where's the need? You can already do:
class MyError(ValueError, TypeError): ...
etc.?
Gerrit.