In Python 2.7.x, I've created an Exception class:
self.args = arg
raise myException("This is a test")
except myException as e:
('T', 'h', 'i', 's', ' ', 'i', 's'...)
args on an exception is special; it expects to be a sequence. Assigning a string to
self.args is legal, it is a sequence, but it is converted to a tuple when you do.
Assign a tuple containing your argument instead:
class myException(RuntimeError): def __init__(self, arg): self.args = (arg,)
The tuple of arguments given to the exception constructor. Some built-in exceptions (like
IOError) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message.