What's the best way to implement an exception stack trace? What I want
is sth like printStackTrace() in Java. It could look like this:
Car.cpp:381:runtime_exception:Could not find the brake
Police.cpp:123:traffic_observation_exception:Speed too high
Driver.cpp:2131:existential_exception:I am in jail
for the following fictitious program:
int main(){
try{
Driver me;
me.driveHome(); // starts a chain of exceptions
// of which the last one comes up here
me.watchTV();
}catch(exception& e){
cerr << e.what();
}
}
If we don't have the hierarchy, all the client sees is the last
exception, sth like "I am in jail", but that's not enough! He doesn't
know what's going on, so he needs to see the whole chain of reasons.
Thanks!
Markus 7 2682
Markus Dehmann wrote: What's the best way to implement an exception stack trace? What I want is sth like printStackTrace() in Java. It could look like this:
Unlike Java, C++ doesn't incorporate a debugger into every application.
If you need one you have to provide it. Your compiler typically has one.
Just start it up and run your application.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
On Mon, 05 Jul 2004 13:03:18 -0400, Pete Becker <pe********@acm.org> wrote: Markus Dehmann wrote: What's the best way to implement an exception stack trace? What I want is sth like printStackTrace() in Java. It could look like this:
Unlike Java, C++ doesn't incorporate a debugger into every application. If you need one you have to provide it.
I know that C++ doesn't incorporate it automatically. My question was:
What's the best way to implement such a stack trace (given that
C++ doesn't provide it)...
Is it reasonable to add a list of messages to my exception class? On each
catch, I would add a message (with __FILE, __LINE__ information) to the
caught exception and throw it again, up to the highest level in main().
Markus
Markus Dehmann wrote: What's the best way to implement an exception stack trace? What I want is sth like printStackTrace() in Java. It could look like this:
Car.cpp:381:runtime_exception:Could not find the brake Police.cpp:123:traffic_observation_exception:Speed too high Driver.cpp:2131:existential_exception:I am in jail
for the following fictitious program:
int main(){ try{ Driver me; me.driveHome(); // starts a chain of exceptions // of which the last one comes up here me.watchTV(); }catch(exception& e){ cerr << e.what(); } }
If we don't have the hierarchy, all the client sees is the last exception, sth like "I am in jail", but that's not enough! He doesn't know what's going on, so he needs to see the whole chain of reasons.
Perhaps you could make use of uncaught_exception(), which returns true
during stack unwinding. This must have been thought through and
perfected before, but here is a raw idea offhand:
#include <stdio.h>
#include <exception>
class ExceptionWatch {
int line_;
char const* pfname_;
public:
ExceptionWatch(int line, char const* pfname) : line_(line),
pfname_(pfname) {}
~ExceptionWatch() {
if(std::uncaught_exception()) {
//on purpose
printf("line:\t%d\tfile name:\t%s\n", line_, pfname_);
}
}
};
#define EXCEPTWATCH ExceptionWatch exception_watch(__LINE__, __FILE__);
Insert EXCEPTWATCH at the beginning of each function you want to trace:
void func() {
EXCEPTWATCH
//...
}
Denis
Markus Dehmann wrote: Is it reasonable to add a list of messages to my exception class? On each catch, I would add a message (with __FILE, __LINE__ information) to the caught exception and throw it again, up to the highest level in main().
Seems like a lot of work. What problem are you trying to solve?
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Markus Dehmann wrote: On Mon, 05 Jul 2004 13:03:18 -0400, Pete Becker <pe********@acm.org> wrote:
Markus Dehmann wrote:
What's the best way to implement an exception stack trace? What I want is sth like printStackTrace() in Java. It could look like this:
Unlike Java, C++ doesn't incorporate a debugger into every application. If you need one you have to provide it.
I know that C++ doesn't incorporate it automatically. My question was: What's the best way to implement such a stack trace (given that C++ doesn't provide it)...
[snip]
If you happen to be developing on a system like Linux, then you could
use one of many utilities such as electric fence. These are designed to
provide the platform specific capabilities you seem to be looking for, &
unless I'm mistaken, they tie into GDB.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFA61HPoo/Prlj9GScRAtovAJ0cXxRAN0rjwIxdBH1aXox4/DtqQACeMwjy
PYGqYyeb+vm6KTalitOk+Xo=
=W3px
-----END PGP SIGNATURE-----
Evan Carew <te*******@pobox.com> wrote in message news:<10*************@corp.supernews.com>... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Markus Dehmann wrote: On Mon, 05 Jul 2004 13:03:18 -0400, Pete Becker <pe********@acm.org> wrote:
Markus Dehmann wrote:
What's the best way to implement an exception stack trace? What I want is sth like printStackTrace() in Java. It could look like this:
Unlike Java, C++ doesn't incorporate a debugger into every application. If you need one you have to provide it.
I know that C++ doesn't incorporate it automatically. My question was: What's the best way to implement such a stack trace (given that C++ doesn't provide it)... [snip] If you happen to be developing on a system like Linux, then you could use one of many utilities such as electric fence. These are designed to provide the platform specific capabilities you seem to be looking for, & unless I'm mistaken, they tie into GDB.
Well, I want this stack trace as a final output for the end user. I am
writing a kind of compiler where I process user input. I have a parser
that reads user input and constructs sth called Items or int
primitives. When an expression of the user input cannot be parsed, an
exception is thrown, but also an "UnknownItem" is recognized (derived
from Item), and the system tries to move on with this Item as long as
possible.
So, If sth could not be recognized and an "UnknownItem" is propagated,
later functions might be able to process that or again throw an
exception, e.g. that they ecpected an int, but got an Item (namley,
the UnknownItem). So, there are different stages of errors that the
user all wants to see.
Markus
Markus Dehmann wrote: Well, I want this stack trace as a final output for the end user. I am writing a kind of compiler where I process user input. I have a parser that reads user input and constructs sth called Items or int primitives. When an expression of the user input cannot be parsed, an exception is thrown, but also an "UnknownItem" is recognized (derived from Item), and the system tries to move on with this Item as long as possible.
This doesn't sound like an appropriate use of exceptions. A stack trace
is an implementation detail: if you restructure the application, the
same mistake will produce a different error message. What you need to do
is tell the user what mistake they made, not what you were doing when
you noticed it.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Herring |
last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag
and drop weenie, not a real programmer. So I tend to get confused when
things do not look like the instructions said they...
|
by: cody |
last post by:
public DateTime Value
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text),
int.Parse(tbDay.Text));
}
catch (FormatException)
|
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...
|
by: Barry Mossman |
last post by:
Hi,
I am throwing an exception derived from ApplicationException as follows
catch (Exception ex) {
throw new MyException("message", ex);
}
My exception's constructor is:
public...
|
by: Kevin Yu |
last post by:
is it a bad programming design to throw exception in the try block then
catch it??
| |
by: Aren Cambre |
last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's
BodyFormat = MailFormat.Html? I've searched all over the place and
cannot find a solution anywhere. I am running this on Windows XP...
|
by: Lasse Vågsæther Karlsen |
last post by:
If I got the following code:
try
{
// something that might throw an exception
}
catch (Exception ex)
{
// Log contents of ex here
throw;
|
by: Chris Stiefeling |
last post by:
Hi,
I am experiencing a strange problem. I am reading and writing xml files via
XmlDocument and XmlTextWriter. In the debugger everything works fine but
outside the debugger (debug or release)...
|
by: =?Utf-8?B?UGF1bCBQaGlsbGlwcw==?= |
last post by:
I have read many things about this but I haven't got a clear vision on what
to do if anything about this.
I have a system that tries to find holes in my web site. One of the things
it has...
|
by: Scott |
last post by:
I'm debugging an xmlrpc client/server application. Often when an
exception occurs in the server, I receive only a very short error
message on the client. For example:
xmlrpclib.Fault: <Fault 1:...
|
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,...
| |
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |