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

DESCRIPTION

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

EXAMPLE

67       This bgerror procedure appends errors to a file, with a timestamp.
68
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

SEE ALSO

77       after(n), errorCode(n), errorInfo(n), interp(n)
78

KEYWORDS

80       background error, reporting
81
82
83
84Tcl                                   7.5                           bgerror(n)
Impressum