Home > Tcl Error > Tcl Error Return

Tcl Error Return

Contents

Typically the info value is supplied from the value left in errorInfo after a catch command trapped an error within the procedure. If result is not specified then an empty string will be returned to the caller as the result of the procedure. There are several ways to capture and access this information. This isn't the case in modern versions of Tcl, which employ byte compilation. have a peek here

In Tcl 7.6 and earlier you could actually get away with things likelindex "a b c {bad{list" 1as long as the examined part of the list was syntactically valid. The return code of the procedure is 0 (TCL_OK). return puts "line 2" ;# This line will not be printed. } Next, an example of using return to set the value returned by the procedure. Any exceptional return code (non-TCL_OK) returned by a command evaluation causes the flow on to the next command to be interrupted.

Tcl Proc Return Value

If you have proc a that called proc b that called c that called d , if d generates an error, the "call stack" will unwind. 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 For instance,set fp [open foo.bar]leads to the errorcouldn't open "foo.bar": no such file or directorywhich tells it pretty well, and does not terminate the application if it has an event loop

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 Another use case for -code is to have the caller, rather than the current procedure, report that the wrong number of arguments were provided, since this makes the error message more If supplied, info is used to seed the errorInfo value, and code becomes the errorCode, which is otherwise NONE.error is short for return -level 0 -code error, which is not the Tcl Return Array However, the -code option may be used to generate an exceptional return from the procedure.

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 Return List EXAMPLEGenerate an error if a basic mathematical operation fails: if {1+2 != 3} { error "something is very wrong with addition" } SEE ALSO catch(n), return(n) KEYWORDS error, exception Contents Two additional options, -errorinfo and -errorcode, may be used to provide additional information during error returns. The level value must be a non-negative integer representing a number of levels on the call stack.

Join them; it only takes a minute: Sign up What's the difference between return -code error and error up vote 4 down vote favorite 1 What is actually the difference between Tcl Stop Script Similarly, if a command expects a script, you'd better pass it a script.PYK 2013-12-10: However, if lindex is missing its second value, the first value can still be 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 is meant to be in a format that is easy to parse with a script, so that Tcl scripts can examine the contents of this variable, and decide what to

Tcl Return List

These options are ignored unless code is error. http://wiki.tcl.tk/error In the usual case where the -code option is not specified the procedure will return normally. Tcl Proc Return Value If the -errorcode option is specified then code provides a value for the errorCode variable. Tcl Proc Return List Example Two additional options, -errorinfo and -errorcode, may be used to provide additional information during error returns.

The return -code error command makes the procedure it is placed in produce an error (as if the procedure was error); it's great for the case where there's a problem with http://colinmeldrum.com/tcl-error/tcl-last-error.html Otherwise it is 1. return ?option value ...? ?result? Code may have any of the following values: ok Normal return: same as if the option is omitted. Tcl Error Handling

Not the answer you're looking for? There are currently only three such "expected" error returns: DB_NOTFOUND: No matching key/data pair found DB_KEYEMPTY: Nonexistent key/data pair DB_KEYEXIST: Key/data pair already exists Finally, sometimes Berkeley DB will output additional If the procedure invocation occurred during the evaluation of the body of another procedure, the process will repeat itself up the call stack, decrementing the value of the -level entry at Check This Out It's that simple.jenglish's statement is correct, though it's more philosophical than practical.

current community chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. Tcl Stop Execution In other words, it needs return -level 1 ... 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}

When in doubt, just use error.Show discussionDKF: I find that it is best to use error (or throw) when it is an internal problem of the code, and return -code error

Hot Network Questions How to make a comic in blender? Synopsis edit error message ?info? ?code? If a result argument is provided, its value becomes the result of the procedure passed back to the caller. Tcl Errorinfo See below for additional options.

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. more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed It's therefore unwise, and one could argue even illegal, to pass in something that's not at least syntactically valid as a script, even if you know that parts of it will this contact form Browse other questions tagged tcl or ask your own question.

If not, the error is placed in varName. value Value must be an integer; it will be returned as the completion code for the current procedure. The -code option is rarely used. How to replace line of code with the value that is returned by string map?2TCL open file and check for error-2Need info about return - in TCL2TCL proc and byte code error (or 1) Error return: the return code of the procedure is 1 (TCL_ERROR).

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. Script evaluation ceases, and the exceptional return code from the command becomes the return code of the full script evaluation.