1bgerror(n)                   Tcl Built-In Commands                  bgerror(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       bgerror - Command invoked to process background errors
9

SYNOPSIS

11       bgerror message
12_________________________________________________________________
13
14

DESCRIPTION

16       Release  8.5  of  Tcl supports the interp bgerror command, which allows │
17       applications to register in an interpreter the command that will handle │
18       background  errors in that interpreter.  In older releases of Tcl, this │
19       level of control was not available, and applications could control  the │
20       handling  of background errors only by creating a command with the par‐ │
21       ticular command name bgerror in the global namespace of an interpreter. │
22       The following documentation describes the interface requirements of the │
23       bgerror command an application might  define  to  retain  compatibility │
24       with  pre-8.5  releases of Tcl.  Applications intending to support only │
25       Tcl releases 8.5 and later should simply make use of interp bgerror.
26
27       The bgerror command does not exist as built-in part of  Tcl.   Instead,
28       individual  applications or users can define a bgerror command (e.g. as
29       a Tcl procedure) if they wish to handle background errors.
30
31       A background error is one that occurs in an event handler or some other
32       command  that  did not originate with the application.  For example, if
33       an error occurs while executing a command specified with the after com‐
34       mand,  then  it is a background error.  For a non-background error, the
35       error can simply be returned up through nested Tcl command  evaluations
36       until it reaches the top-level code in the application; then the appli‐
37       cation can report the error in whatever way it wishes.   When  a  back‐
38       ground error occurs, the unwinding ends in the Tcl library and there is
39       no obvious way for Tcl to report the error.
40
41       When Tcl detects a background error, it  saves  information  about  the
42       error  and invokes a handler command registered by interp bgerror later
43       as an idle event handler.  The default handler command  in  turn  calls
44       the bgerror command .  Before invoking bgerror, Tcl restores the error‐
45       Info and errorCode variables to their values  at  the  time  the  error
46       occurred,  then  it  invokes bgerror with the error message as its only
47       argument.  Tcl assumes that the application has implemented the bgerror
48       command, and that the command will report the error in a way that makes
49       sense for the application.  Tcl will ignore any result returned by  the
50       bgerror command as long as no error is generated.
51
52       If  another  Tcl  error occurs within the bgerror command (for example,
53       because no bgerror command has been defined) then Tcl reports the error
54       itself by writing a message to stderr.
55
56       If  several  background  errors accumulate before bgerror is invoked to
57       process them, bgerror will be invoked once for each error, in the order
58       they  occurred.   However,  if  bgerror returns with a break exception,
59       then any remaining errors are skipped without calling bgerror.
60
61       If you are writing code that will be used by others as part of a  pack‐
62       age  or  other  kind of library, consider avoiding bgerror.  The reason
63       for this is that the application programmer may also want to  define  a
64       bgerror,  or  use other code that does and thus will have trouble inte‐
65       grating your code.
66

EXAMPLE

68       This bgerror procedure appends errors to a file, with a timestamp.
69              proc bgerror {message} {
70                  set timestamp [clock format [clock seconds]]
71                  set fl [open mylog.txt {WRONLY CREAT APPEND}]
72                  puts $fl "$timestamp: bgerror in $::argv '$message'"
73                  close $fl
74              }
75
76

SEE ALSO

78       after(n), interp(n), tclvars(n)
79
80

KEYWORDS

82       background error, reporting
83
84
85
86Tcl                                   7.5                           bgerror(n)
Impressum