<br><br><div class="gmail_quote">On Wed, Sep 16, 2009 at 11:39 AM, Vishal <span dir="ltr">&lt;<a href="mailto:vsapre80@gmail.com">vsapre80@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<font face="&#39;courier new&#39;, monospace"><span style="font-size: small;"><br><br></span></font><div class="gmail_quote"><div class="im"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">On Tue, Sep 15, 2009 at 9:07 PM, steve </span></font><span dir="ltr"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">&lt;<a href="mailto:steve@lonetwin.net" target="_blank">steve@lonetwin.net</a>&gt;</span></font></span><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;"> wrote:<br>



</span></font></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="im"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">On 09/15/2009 08:56 PM, Vishal wrote:<br>



</span></font>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;"><div class="im">

Hello,<br><br>
I would like to raise an exception of type Exception(), however the<br>
regular exception stack trace needs to be supressed.<br><br>
This is needed in a function that takes raw_input() from the user and<br>
based on &#39;Y&#39; or &#39;N&#39;, the function suspends further execution and returns<br></div>
to the python prompt or Hicontinues. An exit() brings it out of the python<div class="im"><br>
process....where as what is needed is coming back to the python prompt.<br><br>
I want a custom message to appear instead of a regular exception stack<br>
trace message.<br><br>
How to do this? any pointers...?<br></div></span></font>




</blockquote></div><div class="im"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">
Python 2.6 (r26:66714, Jun  8 2009, 16:07:29)<br>
[GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2<br>
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>
&gt;&gt;&gt; import traceback<br>
&gt;&gt;&gt; try:<br>
...     1 + &quot;foo&quot;<br>
... except Exception, e:<br>
...     traceback.format_stack(limit=</span></font><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">1)<br>
...<br>
[&#39;  File &quot;&lt;stdin&gt;&quot;, line 4, in &lt;module&gt;\n&#39;]<br>
&gt;&gt;&gt; help(traceback)<br>
....<br><br>
HTH,<br>
- steve<br></span></font>
<font color="#888888"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">
<br></span></font></font><div><div><font color="#888888"><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;"><br>
</span></font></font>
</div></div></div></blockquote></div><div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;"><br></span></font></div><span style="font-size: small;"><font face="arial, helvetica, sans-serif">Forgot to mention that we are currently stuck with python2.5.2</font></span><div>



<span style="font-size: small;"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><span style="font-size: small;"><font face="arial, helvetica, sans-serif">As part of a debug/test hook, I would like to suspend further action of a program, after a certain point in the procedure. What I had come up with is a function named testHook() which does this:</font></span></div>



<div><span style="font-size: small;"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">def testHook():</span></font></div>



<div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">    &quot;&quot;&quot;</span></font></div><div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">    &quot;&quot;&quot;</span></font></div>



<div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">    choice = raw_input(&quot;Would you like to continue (Y or N): &quot;)</span></font></div>
<div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">    try:</span></font></div><div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">        if(str(choice).lower() != &#39;y&#39;):</span></font></div>



<div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">            print(&quot;You chose not to go ahead. Ok!!\nAborting Now...&quot;)</span></font></div>
<div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">            raise Exception(&quot;User initiated Abort...&quot;)</span></font></div><div>
<font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">    except Exception:</span></font></div><div><font face="&#39;courier new&#39;, monospace"><span style="font-size: small;">        raise # re-raise it..so we come out of execution loop</span></font></div>



<div><br></div></div></blockquote><div><br>is this what you want, <br><br>def testHook():<br>    &quot;&quot;&quot; <br>    &quot;&quot;&quot;<br>    choice = raw_input(&quot;Would you like to continue (Y or N): &quot;)<br>
    try:<br>        if(str(choice).lower() != &#39;y&#39;):<br>            print(&quot;You chose not to go ahead. Ok!!\nAborting Now...&quot;)<br>            raise Exception(&quot;User initiated Abort...&quot;)<br>    except Exception, e:<br>
        print e.message<br>        <br><br><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><div></div>In this case, a stack trace gets printed out, before the string &#39;user initiated abort&#39; comes up. I want to remove that stack trace...so it looks more clean to a user.</div>
<div><br></div><div>What can be done in this case? or any other way of creating such a hook?</div><div><div></div><div class="h5">

<div><br>-- <br>Thanks and best regards,<br>Vishal Sapre<br><br>
</div>
</div></div><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>ashok raavi<br>