Home > Return Code > Tcl Proc Return Value

Tcl Proc Return Value


Tcl's initial error stack 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 How do I dehumanize a humanoid alien? Getting Tcl/Tk Getting help Learning Tcl Tcl Dev Xchange About the Wiki Community Advocacy Conferences Chat, news, lists History Humor People Tcl websites Reference Companies Getting help Online books Online tutorials Otherwise usage of the return -code option is mostly limited to procedures that implement a new control structure. have a peek at these guys

Synopsis edit return ?result return ?-code code? ?result return ?option value? ?result Options edit-errorcode list-errorinfo info-errorstack listadded in Tcl8.6-level level-options options Documentation editofficial referenceTIP 90, Enable return -code in Control Structure These commands can make use of exceptional return codes to enable special features. Use in pkgIndex.tcl editSee package index script interface guidelines for another use of return in source'd scripts: The main use for return outside procedures is in pkgIndex.tcl:if {![package vsatisfies [package provide continue (4) The return code of the procedure is 4 (TCL_CONTINUE).

Tcl Proc Return Value

Coup: Can you assassinate yourself? Again, what's needed is return -level 1 -code error instead of return -level 0 -code error.Two additional options, -errorinfo and -errorcode, may be used to provide additional information during error returns. proc printOneLine {} { puts "line 1" ;# This line will be printed. Example: Catch return editExample for caught return, from a posting of George Petasis in comp.lang.tcl:% proc foo {} { puts "catch result is :[catch { return}]" puts "after return" } %

However, the -code option may be used to generate an exceptional return from the procedure. If after decrementing, the value of the -level entry is 0, then the value of the -code entry becomes the return code of the procedure. But we get only the last byte of the exit code.example: the original failure & exit code is 655, the exit code in tcl via errorCode is 143 (655 & 255 Exec In Tcl Examples Best regards , tcl exec echo tshark share|improve this question asked Mar 27 '15 at 14:18 Aymen Badri 53 add a comment| 1 Answer 1 active oldest votes up vote 1

finally ...kbk 2000-12-14: A pure-Tcl implementation of a Java-style try construct, along with a worked example of catching break, continue, error, return.ucatchDeunicodifies the error message. Tcl Exec Return Value DESCRIPTION Return immediately from the current procedure (or top-level command or source command), with string as the return value. yieldTo is also related to tailcall in that it has a custom continuation. The -errorinfo option specifies an initial stack trace for the errorInfo variable; if it is not specified then the stack trace left in errorInfo will include the call to the procedure

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 Catch Command In Tcl If you want to use this approach in a more robust and fast manner, you may want to defineproc throw {{msg {}} {code 10}} { return -code $code $msg }This will One real possibility which would upset Tcl in any event is if the text following [return] contains mismatched braces.And last, I really ought to mention that the first time Tcl runs Pseudo-currying in one line How do manufacturers detune engines?

Tcl Exec Return Value

bash tcl share|improve this question asked Aug 24 '11 at 14:55 tgai 65911224 It's not clear whether you're asking how to trap a return value in TCL, or how Typically the info value is supplied from the value left in $errorInfo when catch traps an error within the procedure.If -errorcode is specified, list provides a value for $errorCode. Tcl Proc Return Value A Tcl script is a sequence of Tcl commands. Tcl Error Command By far the most common use case is to return a value from the current procedure:proc knightswhosay {} { return Ni! }-level is a positive integer indicating the number of levels

If no -level option is provided, the default value of level is 1, so that return sets the return code that the current procedure returns to its caller, 1 level up More about the author How can I monitor the progress of a slow upgrade? In Java, you can have a variety of exceptions, each represented by a different class, that signal different types of error conditions. In that circumstance, the -level entry in the return options dictionary is decremented. Tcl Return List

What would be a good choice for a controlled opposition? Any suggestions? Description editcatch is used to intercept the return code from the evaluation of script, which otherwise would be used by the interpreter to decide how to proceed: Whether an error occurred, check my blog Resources Join | Advertise Copyright © 1998-2016, Inc.

Tcl has no throw command, but still you can call it. Tcl Exec Return Code The recommendation frequently is to usecatch {exec somecommand &}However, what would be a strategy if you wanted to catch the output and somecommand's return code?HaO: Use open and a command pipe, Why call it a "major" revision if the suggested changes are seemingly minor?

Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

See below for additional options. DESCRIPTION EXCEPTIONAL RETURN CODES ok (or 0) error (1) return (2) break (3) continue (4) value EXAMPLES SEE ALSO KEYWORDS NAME return - Return from a procedure SYNOPSIS return ?-code code? proc returnX {} {return X} puts [returnX] ;# prints "X" Next, a more complete example, using return -code error to report invalid arguments. Tcl Error Handling Also see UNIX only exec wrapper.On comp.lang.tcl, Ulrich Schoebel shows this as an example of how to get at the exit code of a command being exec'd in Tcl:if {[catch {exec

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 Then info is the initial stack trace, meant to provide to a human reader additional information about the context in which the error occurred. If no -errorstack option is provided to return when the -code error option is provided, Tcl will provide its own initial error stack in the entry for -errorstack. Join them; it only takes a minute: Sign up getting exit code of an executed sipp with tcl up vote 0 down vote favorite I'm trying to get the exit code

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. User-defined behaviour. It is perfectly reasonable to catch "large" chunks:if { [ catch { puts $fid "Here's my last message." close $fid } err ] } { catch { close $fid } return return -level 0 -code break is the same as break. (TCL_BREAK)4continueInstruct the next level up to terminate the current iteration of the innermost nested loop in the code that invoked the

This isn't the case in modern versions of Tcl, which employ byte compilation. exec and error information Updated 2016-07-30 14:14:47 by dkf ▲ Arjen Markus (27 february 2003) The exec command will return an error whenever the program (or process) that was invoked The catch command may be used to capture all of this information -- the return code, the result, and the return options dictionary -- that arise from evaluation of a script. These options are ignored unless -code is error.-errorinfo specifies an initial stack trace for $errorInfo.

Then in a "try" block, you can test for the different types of error conditions separately and handle them in different ways. (My complaint about Java is that there seems to Script evaluation ceases, and the exceptional return code from the command becomes the return code of the full script evaluation. The procedure command behaves in its calling context as if it were the command break. The error stack will also be reachable through info errorstack.