Obtaining the line reached in a source command without terminating the command

Obtaining the line reached in a source command without terminating the command

Post by Jeff Hobb » Mon, 25 Aug 2003 02:26:05

$::errorInfo is available at any time, containing the info from the
last error thrown. If an error just occured, you can access it, but
I don't quite understand what you are trying to do. If you look at
the tkcon hot errors functionality, you will see how one can do some
magic with errorInfo data (when an error is thrown in tkcon, you can
click on it to bring up a new window that has extra highlighting for
any function info it finds to bring up more windows with those
functions, right to the point of the error).

Jeff Hobbs The Tcl Guy
Senior Developer http://www.yqcomputer.com/
Tcl Support and Productivity Solutions

Obtaining the line reached in a source command without terminating the command

Post by Steve Bol » Wed, 27 Aug 2003 16:14:04

The context is this: I have an application mostly writting in C++,
with an embedded Tcl interpreter. The application can be automatically
tested by running Tcl scripts. Tests can register Tcl commands to be
evaluated by the application when particular events or state changes
occur within the application.

A test may find that one of the commands it registers has been called
unexpectedly. It would like to indicate a test failure and report the line
reached in the Tcl test script at the time this unexpected call was made.

However, the test script has invoked functionality implemented in C++
and the C++ code is simply providing a change notification mechanism
that calls back into Tcl. It was not intended to support the notion that
an operation can fail because one of its change observers doesn't like it.
Therefore, if the callback script errors out, the error will be caught within
the C++ code and the original command, called from the test script
will return TCL_OK. Of course, this means that there's no error and
so nothing to go in $errorInfo.

Obviously, the test script can indicate that the test has failed. However,
obtaining the line number reached in the test script being sourced seems to require
one of three things:
* the C++ source keeps track of the errors detected by the test and
arranges that the Tcl commands it exposes returns TCL_ERROR
following a test failure
* the test script checks its status information following each call
and calls 'error' on test failure to get the context into $errorInfo
* the test script provides its own implementation of 'source' which
makes the current line number available without a Tcl error being

I just wondered if there was an easier way.