[BangPypers] suppressing the exception stack trace
ashok.raavi at gmail.com
Wed Sep 16 08:25:51 CEST 2009
On Wed, Sep 16, 2009 at 11:39 AM, Vishal <vsapre80 at gmail.com> wrote:
> On Tue, Sep 15, 2009 at 9:07 PM, steve <steve at lonetwin.net> wrote:
>> On 09/15/2009 08:56 PM, Vishal wrote:
>>> I would like to raise an exception of type Exception(), however the
>>> regular exception stack trace needs to be supressed.
>>> This is needed in a function that takes raw_input() from the user and
>>> based on 'Y' or 'N', the function suspends further execution and returns
>>> to the python prompt or Hicontinues. An exit() brings it out of the
>>> process....where as what is needed is coming back to the python prompt.
>>> I want a custom message to appear instead of a regular exception stack
>>> trace message.
>>> How to do this? any pointers...?
>> Python 2.6 (r26:66714, Jun 8 2009, 16:07:29)
>> [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import traceback
>> >>> try:
>> ... 1 + "foo"
>> ... except Exception, e:
>> ... traceback.format_stack(limit=1)
>> [' File "<stdin>", line 4, in <module>\n']
>> >>> help(traceback)
>> - steve
> Forgot to mention that we are currently stuck with python2.5.2
> 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:
> def testHook():
> choice = raw_input("Would you like to continue (Y or N): ")
> if(str(choice).lower() != 'y'):
> print("You chose not to go ahead. Ok!!\nAborting Now...")
> raise Exception("User initiated Abort...")
> except Exception:
> raise # re-raise it..so we come out of execution loop
is this what you want,
choice = raw_input("Would you like to continue (Y or N): ")
if(str(choice).lower() != 'y'):
print("You chose not to go ahead. Ok!!\nAborting Now...")
raise Exception("User initiated Abort...")
except Exception, e:
> 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.
> What can be done in this case? or any other way of creating such a hook?
> Thanks and best regards,
> Vishal Sapre
> BangPypers mailing list
> BangPypers at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the BangPypers