Exception Messages
MRAB
python at mrabarnett.plus.com
Mon Oct 15 12:34:50 EDT 2012
On 2012-10-15 17:22, John Gordon wrote:
> In <mailman.2217.1350317845.27098.python-list at python.org> MRAB <python at mrabarnett.plus.com> writes:
>
>> > Why wasn't the message printed out?
>>
>> You didn't add a __str__ method:
>
>> class PvCamError(Exception):
>> def __init__(self, msg):
>> self.msg = msg
>> def __str__(self):
>> return self.msg
>
> Wouldn't PvCamError inherit __str__() from Exception?
>
Yes, but you've put the message in msg, and Exception doesn't have that
attribute.
An alternative approach would be:
class PvCamError(Exception):
pass
More information about the Python-list
mailing list