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 |
---|
15 | error \- Generate an error |
---|
16 | .SH SYNOPSIS |
---|
17 | \fBerror \fImessage\fR ?\fIinfo\fR? ?\fIcode\fR? |
---|
18 | .BE |
---|
19 | |
---|
20 | .SH DESCRIPTION |
---|
21 | .PP |
---|
22 | Returns a \fBTCL_ERROR\fR code, which causes command interpretation to be |
---|
23 | unwound. \fIMessage\fR is a string that is returned to the application |
---|
24 | to indicate what went wrong. |
---|
25 | .PP |
---|
26 | The \fB\-errorinfo\fR return option of an interpreter is used |
---|
27 | to accumulate a stack trace of what was in progress when an |
---|
28 | error occurred; as nested commands unwind, |
---|
29 | the Tcl interpreter adds information to the \fB\-errorinfo\fR |
---|
30 | return option. If the \fIinfo\fR argument is present, it is |
---|
31 | used to initialize the \fB\-errorinfo\fR return options and |
---|
32 | the first increment of unwind information |
---|
33 | will not be added by the Tcl interpreter. |
---|
34 | In other |
---|
35 | words, the command containing the \fBerror\fR command will not appear |
---|
36 | in the stack trace; in its place will be \fIinfo\fR. |
---|
37 | Historically, this feature had been most useful in conjunction |
---|
38 | with the \fBcatch\fR command: |
---|
39 | if a caught error cannot be handled successfully, \fIinfo\fR can be used |
---|
40 | to return a stack trace reflecting the original point of occurrence |
---|
41 | of the error: |
---|
42 | .CS |
---|
43 | \fBcatch {...} errMsg |
---|
44 | set savedInfo $::errorInfo |
---|
45 | \&... |
---|
46 | error $errMsg $savedInfo\fR |
---|
47 | .CE |
---|
48 | When working with Tcl 8.5 or later, the following code |
---|
49 | should be used instead: |
---|
50 | .CS |
---|
51 | \fBcatch {...} errMsg options |
---|
52 | \&... |
---|
53 | return -options $options $errMsg\fR |
---|
54 | .CE |
---|
55 | .PP |
---|
56 | If the \fIcode\fR argument is present, then its value is stored |
---|
57 | in the \fB\-errorcode\fR return option. The \fB\-errorcode\fR |
---|
58 | return option is intended to hold a machine-readable description |
---|
59 | of the error in cases where such information is available; see |
---|
60 | the \fBreturn\fR manual page for information on the proper format |
---|
61 | for this option's value. |
---|
62 | .SH EXAMPLE |
---|
63 | Generate an error if a basic mathematical operation fails: |
---|
64 | .CS |
---|
65 | if {1+2 != 3} { |
---|
66 | \fBerror\fR "something is very wrong with addition" |
---|
67 | } |
---|
68 | .CE |
---|
69 | |
---|
70 | .SH "SEE ALSO" |
---|
71 | catch(n), return(n) |
---|
72 | |
---|
73 | .SH KEYWORDS |
---|
74 | error |
---|