OSDN Git Service

bba4854237b2c901992119eb0b4fe3c871851c1a
[pf3gnuchains/sourceware.git] / tcl / doc / return.n
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$
9 '\" 
10 .so man.macros
11 .TH return n 7.0 Tcl "Tcl Built-In Commands"
12 .BS
13 '\" Note:  do not modify the .SH NAME line immediately below!
14 .SH NAME
15 return \- Return from a procedure
16 .SH SYNOPSIS
17 \fBreturn \fR?\fB\-code \fIcode\fR? ?\fB\-errorinfo \fIinfo\fR? ?\fB\-errorcode\fI code\fR? ?\fIstring\fR?
18 .BE
19
20 .SH DESCRIPTION
21 .PP
22 Return immediately from the current procedure
23 (or top-level command or \fBsource\fR command),
24 with \fIstring\fR as the return value.  If \fIstring\fR is not specified then
25 an empty string will be returned as result.
26
27 .SH "EXCEPTIONAL RETURNS"
28 .PP
29 In the usual case where the \fB\-code\fR option isn't
30 specified the procedure will return normally (its completion
31 code will be TCL_OK).
32 However, the \fB\-code\fR option may be used to generate an
33 exceptional return from the procedure.
34 \fICode\fR may have any of the following values:
35 .TP 10
36 \fBok\fR
37 Normal return:  same as if the option is omitted.
38 .TP 10
39 \fBerror\fR
40 Error return: same as if the \fBerror\fR command were used to
41 terminate the procedure, except for handling of \fBerrorInfo\fR
42 and \fBerrorCode\fR variables (see below).
43 .TP 10
44 \fBreturn\fR
45 The current procedure will return with a completion code of
46 TCL_RETURN, so that the procedure that invoked it will return
47 also.
48 .TP 10
49 \fBbreak\fR
50 The current procedure will return with a completion code of
51 TCL_BREAK, which will terminate the innermost nested loop in
52 the code that invoked the current procedure.
53 .TP 10
54 \fBcontinue\fR
55 The current procedure will return with a completion code of
56 TCL_CONTINUE, which will terminate the current iteration of
57 the innermost nested loop in the code that invoked the current
58 procedure.
59 .TP 10
60 \fIvalue\fR
61 \fIValue\fR must be an integer;  it will be returned as the
62 completion code for the current procedure.
63 .LP
64 The \fB\-code\fR option is rarely used.
65 It is provided so that procedures that implement
66 new control structures can reflect exceptional conditions back to
67 their callers.
68 .PP
69 Two additional options, \fB\-errorinfo\fR and \fB\-errorcode\fR,
70 may be used to provide additional information during error
71 returns.
72 These options are ignored unless \fIcode\fR is \fBerror\fR.
73 .PP
74 The \fB\-errorinfo\fR option specifies an initial stack
75 trace for the \fBerrorInfo\fR variable;  if it is not specified then
76 the stack trace left in \fBerrorInfo\fR will include the call to
77 the procedure and higher levels on the stack but it will not include
78 any information about the context of the error within the procedure.
79 Typically the \fIinfo\fR value is supplied from the value left
80 in \fBerrorInfo\fR after a \fBcatch\fR command trapped an error within
81 the procedure.
82 .PP
83 If the \fB\-errorcode\fR option is specified then \fIcode\fR provides
84 a value for the \fBerrorCode\fR variable.
85 If the option is not specified then \fBerrorCode\fR will
86 default to \fBNONE\fR.
87
88 .SH KEYWORDS
89 break, continue, error, procedure, return