Re: Printing line number of an error [message #34110] |
Sun, 16 February 2003 15:07 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
K Banerjee (kbanerjee@ucwphilly.rr.com) writes:
> Say I encounter an error at line 23 of the file mycode.pro. Is there
> a way to print something like:
>
> ERROR: At line [23] in file [mycode.pro].
>
> I looked at the system variables, but found nothing appropriate.
Well, that is exactly what comes back from the error
message and the traceback that it generates automatically.
I inserted a "Print, xx" statement in line
23 of the program I have in front of me. Here is the
error message:
Trace Error Report from TC_FIX_OVERLAY::EVENTHANDLER:
% PRINT: Variable is undefined: XX.
% Execution halted at: TC_POINT_UTILITY 23 C:\PM\tc_point_utility.pro
% TC_FIX_OVERLAY::EVENTHANDLER 73 C:\PM\tc_fix_overlay__define.pro
% CONTROLPANEL::EVENTHANDLER 199 C:\PM\controlpanel__define.pro
% WIDGETATOM::EVENTHANDLER 132 C:\PM\widgetatom__define.pro
% EVENTDISPATCHER 57 C:\PM\eventdispatcher.pro
% $MAIN$
I can see that the error occurred at line 23 in the program
file tc_point_utility.pro. I *got* to that line in my program
by generating an event from the $MAIN$ level that went through
my eventdispatcher.pro code (at line 57), to my WidgetAtom event
handler (at line 132), to my ControlPanel event handler (at line 199),
to my TC_Fix_Overlay event handler (at line 73), and finally
into my TC_Point_Utility program at line 23.
This particular error message was formatted by going
through my ERROR_MESSAGE program after being caught
with a CATCH error handler, but it simply uses the
standard error traceback information that is presented
for any error occurring in IDL.
If you only wanted the first line of the traceback information,
you could easily modify ERROR_MESSAGE to provide just this.
http://www.dfanning.com/programs/error_message.pro
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|