<font face="'courier new', monospace"><span style="font-size:small"><br><br></span></font><div class="gmail_quote"><font face="'courier new', monospace"><span style="font-size:small">On Tue, Sep 15, 2009 at 9:07 PM, steve </span></font><span dir="ltr"><font face="'courier new', monospace"><span style="font-size:small"><<a href="mailto:steve@lonetwin.net" target="_blank">steve@lonetwin.net</a>></span></font></span><font face="'courier new', 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="'courier new', 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="'courier new', 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 'Y' or 'N', 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="'courier new', 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 "help", "copyright", "credits" or "license" for more information.<br>
>>> import traceback<br>
>>> try:<br>
... 1 + "foo"<br>
... except Exception, e:<br>
... traceback.format_stack(limit=</span></font><font face="'courier new', monospace"><span style="font-size:small">1)<br>
...<br>
[' File "<stdin>", line 4, in <module>\n']<br>
>>> help(traceback)<br>
....<br><br>
HTH,<br>
- steve<br></span></font>
<font color="#888888"><font face="'courier new', monospace"><span style="font-size:small">
<br></span></font></font><div><div><font color="#888888"><font face="'courier new', monospace"><span style="font-size:small"><br>
</span></font></font>
</div></div></blockquote></div><div><font face="'courier new', 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="'courier new', monospace"><span style="font-size:small">def testHook():</span></font></div>
<div><font face="'courier new', monospace"><span style="font-size:small"> """</span></font></div><div><font face="'courier new', monospace"><span style="font-size:small"> """</span></font></div>
<div><font face="'courier new', monospace"><span style="font-size:small"> choice = raw_input("Would you like to continue (Y or N): ")</span></font></div>
<div><font face="'courier new', monospace"><span style="font-size:small"> try:</span></font></div><div><font face="'courier new', monospace"><span style="font-size:small"> if(str(choice).lower() != 'y'):</span></font></div>
<div><font face="'courier new', monospace"><span style="font-size:small"> print("You chose not to go ahead. Ok!!\nAborting Now...")</span></font></div>
<div><font face="'courier new', monospace"><span style="font-size:small"> raise Exception("User initiated Abort...")</span></font></div><div>
<font face="'courier new', monospace"><span style="font-size:small"> except Exception:</span></font></div><div><font face="'courier new', 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 'user initiated abort' 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>