Home > Tcl Error > Tcl Error Return Code

Tcl Error Return Code

Contents

Already a member? EXCEPTIONAL RETURN CODES In addition to the result of a procedure, the return code of a procedure may also be set by return through use of the -code option. interp alias {} Break {} return -level 0 -code break An example of using catch and return -options to re-raise a caught error: proc doSomething {} { set resource [allocate] catch Otherwise usage of the return -code option is mostly limited to procedures that implement a new control structure. have a peek here

SEE ALSO break(n), continue(n), dict(n), error(n), info(n), return(n), tclvars(n) KEYWORDS catch, error, exception Contents Index Keywords About... The return code of the return command itself triggers this special handling by procedure invocation. The procedure command behaves in its calling context as if it were the command break. If evaluation of the loop body returns the return code of TCL_BREAK or TCL_CONTINUE, the loop command can react in such a way as to give the break and continue commands

Tcl Proc Return Value

Registration on or use of this site constitutes acceptance of our Privacy Policy. DESCRIPTION Return immediately from the current procedure (or top-level command or source command), with string as the return value. The -errorcode return option will also be stored in the global variable errorCode. -errorinfo info The -errorinfo option receives special treatment only when the value of the -code option is TCL_ERROR.

This code fragment is useful in scripts to act as a general problem trap: proc main {} { # ... error (or 1) Error return: the return code of the procedure is 1 (TCL_ERROR). How can I diagnose possible problems with my breadboards? Tcl Error Handling if { [catch {open $someFile w} fid] } { puts stderr "Could not open $someFile for writing\n$fid" exit 1 } There are more complex examples of catch usage in the documentation

Evaluates and executes script. Tcl Return List The entries of that dictionary are treated as additional option value pairs for the return command. RETURN CODE HANDLING MECHANISMS Return codes are used in Tcl to control program flow. Tcl packages may provide commands that set other entries in the dictionary of return options, and the return command may be used by scripts to set return options in addition to Then list is the initial error stack, recording actual argument values passed to each proc level.

This is the mechanism by which errors during script evaluation cause an interruption and unwinding of the call stack. Tcl Errorinfo Talk With Other Members Be Notified Of ResponsesTo Your Posts Keyword Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, It's Free! Tcl's initial stack trace will include only the call to the procedure, and stack unwinding will append information about higher stack levels, but there will be no information about the context Then the list value is meant to be additional information about the error, presented as a Tcl list for further processing by programs.

Tcl Return List

It is provided so that procedures that implement new control structures can reflect exceptional conditions back to their callers. Any other value for the -level option (including the default value of 1) will cause the return code of the return command itself to be TCL_RETURN, triggering a return from the Tcl Proc Return Value Then info is the initial stack trace, meant to provide to a human reader additional information about the context in which the error occurred. Tcl Proc Return List Example The return command serves a similar function within script files that are evaluated by the source command.

No list indexing means no requirement to be a list. navigate here Is either Ghost Rider or Mortal Kombat's Scorpion a derivative of the other? Two additional options, -errorinfo and -errorcode, may be used to provide additional information during error returns. Then info is the initial stack trace, meant to provide to a human reader additional information about the context in which the error occurred. Tcl Return Array

These commands can make use of exceptional return codes to enable special features. right, how can i do that intcl ?thanks in advance.-Kamma RE: get exit staus of command in tcl feherke (Programmer) 25 Apr 12 06:40 HiYou mean, when you exec an external error (1) Error return: the return code of the procedure is 1 (TCL_ERROR). Check This Out The value of the -errorcode entry is additional information about the error stored as a list.

return ?-code code? ?-errorinfo info? ?-errorcode errorcode? ?value? Tcl Catch Example Hot Network Questions What are some counter-intuitive results in mathematics that involve only finite objects? If [return] is redefined, code following the [return] could certainly come into play.

return -code error editRS 2005-08-08: Using return -code error in place of plain error, you get a leaner error traceback which is possibly better to read:% proc 1 x {if {$x<=0}

Join UsClose RETURN OPTIONS In addition to a result and a return code, evaluation of a command in Tcl also produces a dictionary of return options. Login with LinkedIN Or Log In Locally Email Password Remember Me Forgot Password?Register ENGINEERING.com Eng-Tips Forums Tek-Tips Forums Search Posts Find A Forum Thread Number Find An Expert Resources Jobs Tcl Stop Execution If it is not specified, the stack trace left in $errorInfo will include the call to the procedure and higher levels on the stack but it will not include any information

Since d generates an error, c will not complete execution cleanly, and will have to pass the error up to b , and in turn on to a. Otherwise it is 1. The -errorcode return option will also be stored in the global variable errorCode. -errorinfo info The -errorinfo option receives special treatment only when the value of the -code option is TCL_ERROR. this contact form return puts "line 2" ;# This line will not be printed. } Next, an example of using return to set the value returned by the procedure.

However, this was more of an accidental artifact of implementation details than anything guaranteed by the language, and in fact this raises an error in more recent Tcl versions. The salient differences with respect to -errorinfo are that: it is a machine-readable form that is amenable to processing with [foreach {tok prm} ...], it contains the true (substituted) values passed proc factorial {n} { if {![string is integer $n] || ($n < 0)} { return -code error \ "expected non-negative integer,\ but got \"$n\"" } if {$n < 2} { return Any exceptional return code (non-TCL_OK) returned by a command evaluation causes the flow on to the next command to be interrupted.

The value of the -errorline entry is an integer indicating which line of script was being evaluated when the error occurred. So long as each command evaluation returns a return code of TCL_OK, evaluation will continue to the next command in the script. exit 2 } SEE ALSOexec(n) KEYWORDS abort, exit, process Contents Index Keywords About... However, the -code option may be used to generate an exceptional return from the procedure.

Typically the info value is supplied from the value left in errorInfo after a catch command trapped an error within the procedure. Two additional options, -errorinfo and -errorcode, may be used to provide additional information during error returns. The entries of that dictionary are treated as additional option value pairs for the return command. RETURN CODE HANDLING MECHANISMS Return codes are used in Tcl to control program flow. The token may be "CALL", in which case the parameter is a list made of the proc name and arguments at the corresponding level; or it may be "UP", in which

value Value must be an integer; it will be returned as the return code for the current procedure. The -code option is rarely used. The formatted stack trace is meant to be read by a person. The return code of the return command itself triggers this special handling by procedure invocation. The procedure command behaves in its calling context as if it were the command error result.

In the usual case where the -code option is not specified the procedure will return normally. Generates an error condition and forces the Tcl call stack to unwind, with error information being added at each step. The catch command calls the Tcl interpreter recursively to execute script, and always returns without raising an error, regardless of any errors that might occur while executing script. return vs falling off the end of the proc editPYK 2016-09-15: Historically, return at the end of a procedure was slightly more performant than a final command that didn't explicitly return.

Why were weapons like Mandrakes and Acromantula, which kill indiscriminately, used in the Battle of Hogwarts? return puts "line 2" ;# This line will not be printed. } Next, an example of using return to set the value returned by the procedure. Or perhaps the code isn't being executed but rather is being analyzed by Nagelfar, which will surely take issue with the invalidity of the code. Are you aComputer / IT professional?Join Tek-Tips Forums!