473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
3 4337
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Linus Nikander | last post by:
After trying to manually reverse-engineer a piece of code i've been handed using Visio I figure someone must have developed a tool that can do automatically in 5 minutes what took me 2 hours. ...
0
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
1
by: Mark Miller | last post by:
I just recently started getting the above error on a page I am posting MULTIPART/FORM-DATA. We have SoftArtisans FileUp component and Filter installed on the server in question and up until a day...
1
by: D A H | last post by:
I have gotten the same exception in multiple projects. I have solved the underlying problem. My question is if anyone knew of a setting that would cause this exception to be thrown. A...
3
by: Nirbho | last post by:
Hi, I'm newish to C# .Net. I'm doing some error handling in my ASP.net pages. When handling the error in the catch block, I want to pass through the namespace of where the error occured.....
4
by: jf li | last post by:
I have a Asp.net web application and a Asp.net Web service application. The Web application is using HtmlInputFile to get a 50M size of file selected by end user, read the data of this file and...
1
by: Modica82 | last post by:
I have created a contract first web service, and to test i have created a client (asp.net) to attempt to test that my web service is at least communication. But when i call a method i get the...
3
by: John K | last post by:
How do you hide the available functions (and syntax) that are normally displayed when you browse to a webservice (e.g. httpx://xxx.com/CMgr.asmx)? If you go to that page you will see a list of...
3
by: barker7 | last post by:
I am calling an unmanaged C++ method from C#. When an exception occurs in the C++ code, it gets caught in our C# code. CSharpMethod() { try { NativeCPPMethod(); } catch (Exception e)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.