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

Hello,
    when an error occurs during a source of a Tcl script, $errorInfo
will give a helpful message showing which line of the file being sourced
was reached when the error was encountered.

    However, $errorInfo is only available once you've terminated
the commands being evaluted. Suppose I just want a warning message
but one that shows a context similar to that in $errorInfo?
'info level' shows the procedures that are executing.
Is that all that's available or have I missed something?

Thanks,
Steve.



Sun, 05 Feb 2006 00:38:35 GMT  
 Obtaining the line reached in a source command without terminating the command

Quote:

>     when an error occurs during a source of a Tcl script, $errorInfo
> will give a helpful message showing which line of the file being sourced
> was reached when the error was encountered.

>     However, $errorInfo is only available once you've terminated
> the commands being evaluted. Suppose I just want a warning message
> but one that shows a context similar to that in $errorInfo?
> 'info level' shows the procedures that are executing.
> Is that all that's available or have I missed something?

$::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.ActiveState.com/
         Tcl Support and Productivity Solutions



Thu, 09 Feb 2006 01:26:05 GMT  
 Obtaining the line reached in a source command without terminating the command
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
   triggered.

I just wondered if there was an easier way.

Thanks,
Steve.

Quote:


> >     when an error occurs during a source of a Tcl script, $errorInfo
> > will give a helpful message showing which line of the file being sourced
> > was reached when the error was encountered.

> >     However, $errorInfo is only available once you've terminated
> > the commands being evaluted. Suppose I just want a warning message
> > but one that shows a context similar to that in $errorInfo?
> > 'info level' shows the procedures that are executing.
> > Is that all that's available or have I missed something?

> $::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.ActiveState.com/
>          Tcl Support and Productivity Solutions



Sat, 11 Feb 2006 15:14:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How do you obtain command line arguments?

2. PHP command-line interpreter without safe_mode?

3. help me to execute my file without using wish (menu file, command source)

4. Win2000 Gawk Renaming a file with system() command, command line to long

5. command environments and command line arguments

6. Command line variables to executables,command programs

7. command line options for old viscob and vclink commands

8. command line command structure representation

9. Fortran command to read command line argument?

10. System commands and command-line args with g77 on Sun

11. freewrap exec command and source command

12. Serial - ACK command to terminate

 

 
Powered by phpBB® Forum Software