Stack printing in C++

Hi,
I am using exception mechanism as my error handler , but the exception doesnt specify the location of the error , or all the herarchy to the throwing method..so i am thinking to print the stack in addition of printing the exception message whenever an exception is thrown.
is this possible ? ( debuggers do it.)
shadisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
What OS are you talking about?
0
shadisAuthor Commented:
HP UX 10.20
Linux
Win -NT

My first priority is NT and linux
0
shadisAuthor Commented:
sorry , i ment HP and NT
0
nietodCommented:
I would have to say you are trying to use exceptions incorrectly.  The idea behind exceptions is that they are detected at a points where they can't behandled, but presumabely there is a point, farther down the call stack, where they can be handled.  So they point should catch the exception and fix the problem.  That point should not care where the problem was, it should just fix the problem.

That aside, it can (sort of) be done.  You can have the exception objects you throw store the source code file name and line number of the exception location.  These can be suplied to the object's constructor using the __FILE__ and __LINE__ pre-processor synbols.

Althernately you can have the object store the name of the procedure that perfrms the exception.

How that gives you the location of the exception, but not the entire call stack.  You can get that too, but that is a little harder.  You can have define a base class exception object that stores an STL vector to store the call stack information.  (procedure name, and or line number etc.)   Then at the end of each procedure place code that catches every exception (every exception derived from this base class) and have the code add the current procedure's information to the call stack, then rethrow the object with the new information.   You can use some C pre-processor macros to automate this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.