<font face="&#39;courier new&#39;, monospace"><span style="font-size:small"><br><br></span></font><div class="gmail_quote"><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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><font face="&#39;courier new&#39;, monospace"><span style="font-size:small">On 09/15/2009 08:56 PM, Vishal wrote:<br>


</span></font>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="&#39;courier new&#39;, monospace"><span style="font-size:small">
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>
to the python prompt or Hicontinues. An exit() brings it out of the python<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></span></font>




</blockquote></div><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></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>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><br>-- <br>Thanks and best regards,<br>Vishal Sapre<br><br>
</div>