Actually I'm working on linux.
If you're using g++, there are two functions available as an
extension which might interest you: __builtin_return_address and
__builtin_frame_address, see section 5.41 of the g++ manual.
And while I know that it is formally off-topic here, I'd be
interested in the names of the functions in Windows which allow
getting such information. (I've got code which hacks it, in a
very non-portable fashion, but if there is an official solution,
I'd far prefer it.)
Also, the GNU binutils package (generally installed by default
under Linux, but it can be compiled to work with most systems)
has a command addr2line, which can be useful in evaluating the
hex addresses the other techniques will give you.
CException is a code that someone in our software group wrote.
In the ctor for CException the stack is printed out.
Actually, I thought that the C prefix meant that the code came
from one of the Microsoft libraries. At least, MFC seems to use
it rather widely. In which case, it may use tricks that aren't
available to common mortals.
I could take the std library and derive the standards base class
from CException. I was wondering if this is a good way.
Modifying the standard library is definitly NOT a good solution.
Think of the code in the standard library which already uses
std::exception---unless you can recompile this, changing
std::exception is almost sure to result in some sort of wierd
behavior.
This sounds like something that might be worth looking into.
Yes. My usual solution is to use something like:
throw Error( MSG() << ... ) ;
My class Error takes an ErrorMessage as an argument (which it
converts to a string, and logs it; the current version doesn't
add a stack walkback, because I've never found any use for it,
but it wouldn't be hard to add. (MSG() is a macro which ensures
automatic insertion of __FILE__ and __LINE__.) If ErrorMessage
converted implicitly to an std::string, it should be possible to
use it directly in something like std::runtime_error.
In general, however, I've very sceptical about adding things
like stack walkback here---even __FILE__ and __LINE__ are
pushing it. If you need a stack walkback, what you probably
want is an abort, and not an exception.