TABLE OF CONTENTS


::pwtk::catch_error

SYNOPSIS

proc ::pwtk::catch_error {script {errorScript {}}} {

DESCRIPTION

Execute a supplied $script and if an error occurs and $errorScript != {}, execute the $errorScript.

This proc is similar yet different than the Tcl's "try" command. For example, the "::pwtk::error errMsg 1" calls the "exit" command and if ::pwtk::error is called within the catch_error, then "error" is called instead of "exit".

ARGUMENTS

SOURCE

    variable catch_error

    set catch_error 1
    set code [catch {uplevel 1 $script}]
    if { $code == 1 } {
        if { $errorScript != {} } {
            uplevel $errorScript
        }
    }
    set catch_error 0
    if { $code != 1 } {
        return -code $code $code
    } else {
        return $code
    }
}