<br><br><div class="gmail_quote">On Wed, Sep 16, 2009 at 11:39 AM, Vishal <span dir="ltr"><<a href="mailto:vsapre80@gmail.com">vsapre80@gmail.com</a>></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="'courier new', monospace"><span style="font-size: small;"><br><br></span></font><div class="gmail_quote"><div class="im"><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></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="'courier new', 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="'courier new', 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 'Y' or 'N', 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="'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></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></div></blockquote><div><br>is this what you want, <br><br>def testHook():<br> """ <br> """<br> choice = raw_input("Would you like to continue (Y or N): ")<br>
try:<br> if(str(choice).lower() != 'y'):<br> print("You chose not to go ahead. Ok!!\nAborting Now...")<br> raise Exception("User initiated Abort...")<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 '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><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>