Tcl/tk reference-control structure catch

Source: Internet
Author: User

.

.

 

Name

Catch-execute the script and capture errors

Syntax

Catch Script?Resultvarname? ?Optionsvarname?

Description

CatchCommand to prevent the termination of script execution due to an error,CatchThe command can call the Tcl interpreter to execute the script and return the script normally.

If the script produces an error,CatchA non-zero integer is returned. If no error is captured0OrTcl_ OKTCL also defines four exception codes:1(Tcl_error),2(Tcl_return),3(Tcl_break) And4(Tcl_continue). Returns an error when the script is executed.Tcl_error, Other exceptionsReturn,BreakAndContinueCommand generation.

IfResultvarnameVariable. When the returned value is1Stored inResultvarnameIs an error message.0, Stored inResultvarnameIs the script running result.

IfOptionsvarnameVariable, which contains-CodeAnd-LevelTwo entries. If the returned code is notTcl_return,-LevelIs0,-CodeReturns the Exception Code. When the returned code isTcl_return,-LevelAnd-CodeFor other values, seeReturnCommand.

WhenTcl_errorThree additional entries will be addedOptionsvarnameMedium:-Errorinfo,-ErrorcodeAnd-Errorline,-ErrorinfoAn entry is an error message,-ErrorcodeThe entries are some additional information about the error, which is stored as a list,-ErrorlineThe location where the error occurred.-ErrorinfoAnd-ErrorcodeAll entries are recent errors and can be used: ErrorinfoAnd: Errorcode.

Example

CatchThe command can beIfCommand.

if { [catch {open $someFile w} fid] } {
    puts stderr "Could not open $someFile for writing/n$fid"
    exit 1
}

InReturnThe command has more information aboutCatch.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.