By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

Can I hide internal method calls from an exception stack trace?

P: n/a
Is there any way to hide portions of an exception stack trace? When
users get exceptions when using pyparsing, there are usually many
layers of pyparsing-internal stack messages that are not at all
helpful in diagnosing the problem - the intervening messages just
divert the user's attention from the most significant parts of the
stack, usually the user's call into my module, and the root exception
message. For instance, here is a stack trace:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 1065, in
parseString
loc, tokens = self._parse( instring, 0 )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 998, in
_parseCache
value = self._parseNoCache( instring, loc, doActions,
callPreParse )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 941, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 2577, in
parseImpl
return self.expr._parse( instring, loc, doActions,
callPreParse=False )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 998, in
_parseCache
value = self._parseNoCache( instring, loc, doActions,
callPreParse )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 941, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 2325, in
parseImpl
loc, exprtokens = e._parse( instring, loc, doActions )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 998, in
_parseCache
value = self._parseNoCache( instring, loc, doActions,
callPreParse )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 941, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 2577, in
parseImpl
return self.expr._parse( instring, loc, doActions,
callPreParse=False )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 998, in
_parseCache
value = self._parseNoCache( instring, loc, doActions,
callPreParse )
File "/usr/lib/python2.5/site-packages/pyparsing.py", line 943, in
_parseNoCache
raise ParseException( instring, len(instring), self.errmsg, self )
pyparsing.ParseException: Expected ")" (at char 82), (line:1, col:83)

The only helpful content here is just this much:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyparsing.ParseException: Expected ")" (at char 82), (line:1, col:83)

That is, the point in the program where the user's code called
parseString, and the exception raised deep down in the recursive
parser that determined there was a missing closing paren in the input
string being parsed.

Is there any way for me to suppress these non-value-added API-internal
traceback levels?

-- Paul
Nov 7 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Nov 8, 1:25*am, Paul McGuire <pt...@austin.rr.comwrote:
Is there any way for me to suppress these non-value-added API-internal
traceback levels?
Hey Paul,

Have you taken a look at the traceback module?

print_tb(sys.last_traceback, <limit>) or
extract_tb(sys.last_traceback, limit) could do the trick.
Nov 7 '08 #2

P: n/a
Paul McGuire wrote:
Is there any way to hide portions of an exception stack trace? *When
Add a try...except at the appropriate level. Why do you want to do anything
more complex?

Peter

Nov 7 '08 #3

P: n/a
On Nov 7, 10:30*am, Peter Otten <__pete...@web.dewrote:
Paul McGuire wrote:
Is there any way to hide portions of an exception stack trace? *When

Add a try...except at the appropriate level. Why do you want to do anything
more complex?

Peter
I thought I tried that, and now in retrying, I learned a little about
exceptions.

My first attempt was to use this code in the entry method of the API
(parseString):

try:
loc, tokens = self._parse( instring, 0 )
if parseAll:
loc = self.preParse( instring, loc )
StringEnd()._parse( instring, loc )
except ParseBaseException, exc:
raise
else:
return tokens

This didn't change the stack trace at all. But when I change it to
this:

try:
loc, tokens = self._parse( instring, 0 )
if parseAll:
loc = self.preParse( instring, loc )
StringEnd()._parse( instring, loc )
except ParseBaseException, exc:
raise exc
else:
return tokens

Now the stack trace only shows my top-level API method. (I've also
added a little self-explanatory comment as to why I am catching an
exception, just to raise it again.)

Thanks for the nudge in the right direction,
-- Paul
Nov 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.