Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added tcl to libs

File size: 4.0 KB
Line 
1'\"
2'\" Copyright (c) 1990-1994 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: bgerror.n,v 1.13 2007/12/13 15:22:32 dgp Exp $
9'\"
10.so man.macros
11.TH bgerror n 7.5 Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15bgerror \- Command invoked to process background errors
16.SH SYNOPSIS
17\fBbgerror \fImessage\fR
18.BE
19
20.SH DESCRIPTION
21.VS 8.5
22Release 8.5 of Tcl supports the \fBinterp bgerror\fR command,
23which allows applications to register in an interpreter the command
24that will handle background errors in that interpreter.  In older
25releases of Tcl, this level of control was not available, and applications
26could control the handling of background errors only by creating
27a command with the particular command name \fBbgerror\fR in the
28global namespace of an interpreter.  The following documentation
29describes the interface requirements of the \fBbgerror\fR command
30an application might define to retain compatibility with pre-8.5
31releases of Tcl.  Applications intending to support only
32Tcl releases 8.5 and later should simply make use of \fBinterp bgerror\fR.
33.VE 8.5
34.PP
35The \fBbgerror\fR command does not exist as built-in part of Tcl.  Instead,
36individual applications or users can define a \fBbgerror\fR
37command (e.g. as a Tcl procedure) if they wish to handle background
38errors.
39.PP
40A background error is one that occurs in an event handler or some
41other command that did not originate with the application.
42For example, if an error occurs while executing a command specified
43with the \fBafter\fR command, then it is a background error.
44For a non-background error, the error can simply be returned up
45through nested Tcl command evaluations until it reaches the top-level
46code in the application; then the application can report the error
47in whatever way it wishes.  When a background error occurs, the
48unwinding ends in the Tcl library and there is no obvious way for Tcl
49to report the error.
50.PP
51When Tcl detects a background error, it saves information about the
52error and invokes a handler command registered by \fBinterp bgerror\fR
53later as an idle event handler.  The default handler command in turn
54calls the \fBbgerror\fR command .
55Before invoking \fBbgerror\fR, Tcl restores the
56\fBerrorInfo\fR and \fBerrorCode\fR variables to their values at the
57time the error occurred, then it invokes \fBbgerror\fR with the error
58message as its only argument.  Tcl assumes that the application has
59implemented the \fBbgerror\fR command, and that the command will
60report the error in a way that makes sense for the application.  Tcl
61will ignore any result returned by the \fBbgerror\fR command as long
62as no error is generated.
63.PP
64If another Tcl error occurs within the \fBbgerror\fR command (for
65example, because no \fBbgerror\fR command has been defined) then Tcl
66reports the error itself by writing a message to stderr.
67.PP
68If several background errors accumulate before \fBbgerror\fR is
69invoked to process them, \fBbgerror\fR will be invoked once for each
70error, in the order they occurred.  However, if \fBbgerror\fR returns
71with a break exception, then any remaining errors are skipped without
72calling \fBbgerror\fR.
73.PP
74If you are writing code that will be used by others as part of a
75package or other kind of library, consider avoiding \fBbgerror\fR.
76The reason for this is that the application programmer may also want
77to define a \fBbgerror\fR, or use other code that does and thus will
78have trouble integrating your code.
79.SH "EXAMPLE"
80This \fBbgerror\fR procedure appends errors to a file, with a timestamp.
81.CS
82proc bgerror {message} {
83    set timestamp [clock format [clock seconds]]
84    set fl [open mylog.txt {WRONLY CREAT APPEND}]
85    puts $fl "$timestamp: bgerror in $::argv '$message'"
86    close $fl
87}
88.CE
89
90.SH "SEE ALSO"
91after(n), interp(n), tclvars(n)
92
93.SH KEYWORDS
94background error, reporting
Note: See TracBrowser for help on using the repository browser.