Topic: Suggested alteration to standard.
Author: olczyk@interaccess.com (Thaddeus L Olczyk)
Date: Fri, 8 Sep 2000 16:53:56 GMT Raw View
Very simple but petentially usefull.
Add two methods to std::exception
int line(); // returns line that exception was thrown from.
std::string file(); // returns file that exception was thrown from.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Ron Natalie <ron@sensor.com>
Date: Fri, 8 Sep 2000 18:26:52 GMT Raw View
Thaddeus L Olczyk wrote:
>
> int line(); // returns line that exception was thrown from.
> std::string file(); // returns file that exception was thrown from.
And what makes you think the compiler knows this? You're introducing a LOT
of overhead. In addition to what ever the user explicitly throws, the implementation
must carry around file and line for you. This is a lot of overhead that if you need
you can easily do yourself.
#define LINE_EXCEPTION LineException(__FILE__, __LINE__)
struct LineException {
string file;
int line;
LineException(string f, int l) : file(f), line(l) { }
};
try {
throw LINE_EXCEPTION;
} catch(LineException& le) {
cout << "Exception thrown from " << le.file << ":" << le.line << endl;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Per Velschow" <per@velschow.com>
Date: Sun, 10 Sep 2000 00:27:02 GMT Raw View
You are right that this could be very useful for debugging exceptions.
However, it would conflict with one of the basic design criteria for C++:
The zero-overhead rule: "What you don't use, you don't pay for."
It would probably be a better idea to have the compiler emit some
exception-tracking code into the compiled program. (And of course, this
should be an optional behaviour!)
-- Per Velschow
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]