Go to main content

man pages section 1: User Commands

Exit Print View

Updated: Thursday, June 13, 2019

error (1t)


error - Generate an error


error message ?info? ?code?


error(1t)                    Tcl Built-In Commands                   error(1t)


       error - Generate an error

       error message ?info? ?code?

       Returns  a  TCL_ERROR  code,  which causes command interpretation to be
       unwound.  Message is a string that is returned to  the  application  to
       indicate what went wrong.

       The  -errorinfo return option of an interpreter is used to accumulate a
       stack trace of what was in progress when an error occurred;  as  nested
       commands unwind, the Tcl interpreter adds information to the -errorinfo
       return option.  If the info argument is present, it is used to initial-
       ize  the  -errorinfo  return  options and the first increment of unwind
       information will not be added by the Tcl interpreter.  In other  words,
       the  command  containing the error command will not appear in the stack
       trace; in its place will be info.  Historically, this feature had  been
       most  useful  in  conjunction with the catch command: if a caught error
       cannot be handled successfully, info can be  used  to  return  a  stack
       trace reflecting the original point of occurrence of the error:

              catch {...} errMsg
              set savedInfo $::errorInfo
              error $errMsg $savedInfo

       When  working  with Tcl 8.5 or later, the following code should be used

              catch {...} errMsg options
              return -options $options $errMsg

       If the code argument is present,  then  its  value  is  stored  in  the
       -errorcode  return option.  The -errorcode return option is intended to
       hold a machine-readable description of the error in  cases  where  such
       information is available; see the return manual page for information on
       the proper format for this option's value.

       Generate an error if a basic mathematical operation fails:

              if {1+2 != 3} {
                  error "something is very wrong with addition"

       See attributes(7) for descriptions of the following attributes:

       |Availability   | runtime/tcl-8    |
       |Stability      | Uncommitted      |
       catch(n), return(n)

       error, exception

       This    software    was    built    from    source     available     at
       https://github.com/oracle/solaris-userland.    The  original  community
       source was downloaded from  http://prdownloads.sourceforge.net/tcl/tcl-

       Further information about this software can be found on the open source
       community website at https://www.tcl.tk/.

Tcl                                                                  error(1t)