<br><br><div class="gmail_quote">2010/1/9 cool-RR <span dir="ltr"><<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr"><div>I propose that when raising an exception without providing a message, the first line of the docstring will be shown. (I mean shown in the traceback where the message would normally be.</div><div><br></div>
<div>Example session:</div><div><br></div><div>####################################</div><div><br></div><div><div>>>> class MyExcpetion(Exception):</div><div><span style="white-space: pre;"> </span>'''Trying to fit a square piece into a round hole.'''</div>
<div><div><br></div></div></div></div></blockquote><div><br>class MyException(Exception):<br> "Some docstring"<br> def __init__(self, msg=None):<br> if msg == None:<br> msg = self.__doc__<br>
Exception.__init__(self, msg)<br><br>All the best,<br><br>Michael<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">
<div><div><div></div><div>>>> raise MyExcpetion('Problem bla bla')</div><div><br></div><div>Traceback (most recent call last):</div><div> File "<pyshell#3>", line 1, in <module></div>
<div> raise MyExcpetion('Problem bla bla')</div><div>MyExcpetion: Problem bla bla</div></div><div><br></div></div><div><div><div>>>> raise MyExcpetion()</div><div><br></div><div>Traceback (most recent call last):</div>
<div> File "<pyshell#4>", line 1, in <module></div><div> raise MyExcpetion()</div><div>MyExcpetion: Trying to fit a square piece into a round hole.</div><div><br></div><div>####################################</div>
<div><br></div><div>This will be useful for me because I often raise exceptions and have nothing to say besides repeating the exception's docstring, and I have many places in the code where I'd want to conditionally raise it. I'm faced with two choices: Type the exception's docstring in every place, which is lame, and breaks DRY. Or just raise the exception without any message, which may potentially confuse users.</div>
<div><br></div><div>This is the motivation for this suggestion, so I could be succinct without confusing users.</div><div></div></div><div><div><br>
</div><div>What do you think?</div><div><br></div><div>Ram.</div></div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><br><br>