Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/error.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.3 KB
Line 
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: error.n,v 1.11 2007/12/13 15:22:32 dgp Exp $
9'\"
10.so man.macros
11.TH error n "" Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15error \- Generate an error
16.SH SYNOPSIS
17\fBerror \fImessage\fR ?\fIinfo\fR? ?\fIcode\fR?
18.BE
19
20.SH DESCRIPTION
21.PP
22Returns a \fBTCL_ERROR\fR code, which causes command interpretation to be
23unwound.  \fIMessage\fR is a string that is returned to the application
24to indicate what went wrong.
25.PP
26The \fB\-errorinfo\fR return option of an interpreter is used
27to accumulate a stack trace of what was in progress when an
28error occurred; as nested commands unwind,
29the Tcl interpreter adds information to the \fB\-errorinfo\fR
30return option.  If the \fIinfo\fR argument is present, it is
31used to initialize the \fB\-errorinfo\fR return options and
32the first increment of unwind information
33will not be added by the Tcl interpreter. 
34In other
35words, the command containing the \fBerror\fR command will not appear
36in the stack trace; in its place will be \fIinfo\fR.
37Historically, this feature had been most useful in conjunction
38with the \fBcatch\fR command:
39if a caught error cannot be handled successfully, \fIinfo\fR can be used
40to return a stack trace reflecting the original point of occurrence
41of the error:
42.CS
43\fBcatch {...} errMsg
44set savedInfo $::errorInfo
45\&...
46error $errMsg $savedInfo\fR
47.CE
48When working with Tcl 8.5 or later, the following code
49should be used instead:
50.CS
51\fBcatch {...} errMsg options
52\&...
53return -options $options $errMsg\fR
54.CE
55.PP
56If the \fIcode\fR argument is present, then its value is stored
57in the \fB\-errorcode\fR return option.  The \fB\-errorcode\fR
58return option is intended to hold a machine-readable description
59of the error in cases where such information is available; see
60the \fBreturn\fR manual page for information on the proper format
61for this option's value.
62.SH EXAMPLE
63Generate an error if a basic mathematical operation fails:
64.CS
65if {1+2 != 3} {
66    \fBerror\fR "something is very wrong with addition"
67}
68.CE
69
70.SH "SEE ALSO"
71catch(n), return(n)
72
73.SH KEYWORDS
74error
Note: See TracBrowser for help on using the repository browser.