bgerror(n) Tcl Built-In Commands bgerror(n) NAME bgerror - Command invoked to process background errors SYNOPSIS bgerror message DESCRIPTION The bgerror command doesn't exist as built-in part of Tcl. Instead, individual applications or users(1,5) can define a bgerror command (e.g. as a Tcl procedure) if(3,n) they wish to handle background errors. A background error(8,n) is one that occurs in(1,8) an event handler or some other command that didn't originate with the application. For example, if(3,n) an error(8,n) occurs while executing a command specified with the after com- mand, then it is a background error. For a non-background error(8,n), the error(8,n) can simply be returned up through nested Tcl command evaluations until it reaches the top-level code in(1,8) the application; then the appli- cation can report the error(8,n) in(1,8) whatever way it wishes. When a back- ground error(8,n) occurs, the unwinding ends in(1,8) the Tcl library and there is no obvious way for Tcl to report the error. When Tcl detects a background error(8,n), it saves information about the error(8,n) and invokes the bgerror command later as an idle event handler. Before invoking bgerror, Tcl restores the errorInfo and errorCode vari- ables to their values at the time(1,2,n) the error(8,n) occurred, then it invokes bgerror with the error(8,n) message as its only argument. Tcl assumes that the application has implemented the bgerror command, and that the com- mand will report the error(8,n) in(1,8) a way that makes sense for the applica- tion. Tcl will ignore any result returned by the bgerror command as long as no error(8,n) is generated. If another Tcl error(8,n) occurs within the bgerror command (for example, because no bgerror command has been defined) then Tcl reports the error(8,n) itself by writing a message to stderr. If several background errors accumulate before bgerror is invoked to process them, bgerror will be invoked once for each error(8,n), in(1,8) the order they occurred. However, if(3,n) bgerror returns with a break exception, then any remaining errors are skipped without calling bgerror. Tcl has no default implementation for bgerror. However, in(1,8) applications using Tk there is a default bgerror procedure which posts a dialog(1,3,n) box containing the error(8,n) message and offers the user a chance to see a stack trace(3x,n,3x _nc_tracebits) showing where the error(8,n) occurred. In addition to allowing the user to view the stack trace(3x,n,3x _nc_tracebits), the dialog(1,3,n) provides an additional application configurable button which may be used, for example, to save the stack trace(3x,n,3x _nc_tracebits) to a file. By default, this is the behavior associated with that button. This behavior can be redefined by setting the option database values *ErrorDialog.function.text, to specify the caption for the function button, and *ErrorDialog.function.command, to specify the command to be run. The text of the stack trace(3x,n,3x _nc_tracebits) is appended to the com- mand when it is evaluated. If either of these options is set(7,n,1 builtins) to the empty string(3,n), then the additional button will not be displayed in(1,8) the dialog. SEE ALSO after(n), tclvars(n) KEYWORDS background error(8,n), reporting Tcl 7.5 bgerror(n)