12.10.8    Display errors (Debug a Tcl Script)

Debug Tcl Script Example 1.

This script is used to debug an Tcl Script and print errors to BWSPOOL message window. You to enter the name of the Script to be tested in a Text-type tag named TestScriptname. Note that ACTION commands do not usually return errors.  The catch commands displays errors by the built-in Tcl KEYWORD commands. Note that a Tcl script can debug only another Tcl script. Tcl can not debug VB Script or JScript.
The JScript version is at 12.14.8 Display errors (Debug a JScript).
The VB Script version is at 12.17.8 Display errors (Debug a VB Script)


# DebugTclScript.scr - a Tcl script

# Open Message spooler window


# Exit if it calls itself, it will loop endlessly

# trim blank characters

set scriptname [string trim [GETVAL TestScriptname]]

BWSPOOL "Requested script is "

BWSPOOL $scriptname

BWSPOOL "\r\n" #print Carriage return and line feed

if {$scriptname == "DebugTclScript.scr"} then {

 BWSPOOL "don't call itself. Will create an endless loop."



# Run the script put errors in err

catch "SCREXEC [GETVAL TestScriptname]" err


if {[file exists [GETVAL TestScriptname]]} then {

   #figure out if blank - No errors

   set msglength [string length $err]

   if {$msglength <= 0} then {

   set err "No reported errors."


   BWSPOOL $err

 } else {

 BWSPOOL "[GETVAL TestScriptname] ... File not found."


BWSPOOL "\r\n"


Debug Tcl Script Example 2

The following script calls your script (by replacing yourscript.scr with the name of your actual script.  You will also need to create a Graphics Display with:

·         Text Type Screen Tag, 70 characters long named:

·         Rtext field on your graphic display connected to text70.

·         A pushbutton with the keymacro <SCREXEC>@debug1.scr

·         Name this script debug1.scr

Calls script yourscript.scr to be debugged with SCREXEC.
Traps errors with catch and displays if error updates variable err
Sets text values to error message for display


catch {SCREXEC yourscript.scr } err

SETVAL text70=$err

Debug Tcl Script Example 3

The following is another method to display an error in WebAccess scripts


# runs script source.scr - traps and displays if error

# Failed. couldn't read file "sourcein.scr": no such file or directory

# it splits the error in to two tags  using the strung command.  # Errors can be longer than 70 characters,

# the maximum text tag length.

if {[catch [list SCREXEC sourcein.scr] err]} {

   SETVAL "text=Failed. $err "

   SETVAL text50=[string range $err 61 112]


Debug Tcl Script Example 4

Another third version allows you to enter the name of the Script to be tested in a Text-type tag.


# This script calls whatever script is entered in text tag named SCRname

# the scr extension should be added

# SCRERR displays the error on a Display named ScriptTest.bgr

catch {


} err