.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Error 3" .TH Error 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Tk::Error \- Method invoked to process background errors .SH SYNOPSIS .IX Header "SYNOPSIS" Customization: .PP .Vb 1 \& require Tk::ErrorDialog; .Ve .PP or .PP .Vb 4 \& sub Tk::Error \& { \& my ($widget,$error,@locations) = @_; \& ... \& \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The \fBTk::Error\fR method is invoked by perl/Tk when a background error occurs. Two possible implementations are provided in the distribution and individual applications or users can (re)define a \fBTk::Error\fR method (e.g. as a perl sub) if they wish to handle background errors in some other manner. .PP A background error is one that occurs in a command that didn't originate with the application. For example, if an error occurs while executing a callback specified with a bind or a after command, then it is a background error. For a non-background error, the error can simply be returned up through nested subroutines until it reaches the top-level code in the application; then the application can report the error in whatever way it wishes. When a background error occurs, the unwinding ends in the Tk library and there is no obvious way for Tk to report the error. .PP When Tk detects a background error, it saves information about the error and invokes the \fBTk::Error\fR method later when Tk is idle. .PP \&\fBTk::Error\fR is invoked by perl/Tk as if by the perl code: .PP \ \ \ \ \fR\f(CI$mainwindow\fR\fI\fR\->\fBTk::Error\fR(\fI"error message"\fR, \fIlocation ...\fR); .PP \&\fR\f(CI$mainwindow\fR\fI\fR is the \fBMainWindow\fR associated with widget which detected the error, \fI"error message"\fR is a string describing the error that has been detected, \fIlocation\fR is a list of one or more "locations" which describe the call sequence at the point the error was detected. .PP The locations are a typically a mixture of perl location reports giving script name and line number, and simple strings describing locations in core Tk or perl/Tk C code. .PP Tk will ignore any result returned by the \fBTk::Error\fR method. If another error occurs within the \fBTk::Error\fR method (for example if it calls \fBdie\fR) then Tk reports this error itself by writing a message to stderr (this is to avoid infinite loops due to any bugs in \fBTk::Error\fR). .PP If several background errors accumulate before \fBTk::Error\fR is invoked to process them, \fBTk::Error\fR will be invoked once for each error, in the order they occurred. However, if \fBTk::Error\fR calls \fBTk\->break\fR, then any remaining errors are skipped without calling \fBTk::Error\fR. .PP The \fBTk\fR module includes a default \fBTk::Error\fR subroutine that simply reports the error on stderr. .SH Tk::ErrorDialog .IX Header "Tk::ErrorDialog" An alternate definition is provided via: .PP \ \ \ \ \f(CW\*(C`require Tk::ErrorDialog;\*(C'\fR .PP that posts a dialog box containing the error message and offers the user a chance to see a stack trace showing where the error occurred. .PP This is an OO implementation of the Tcl/Tk command \fBbgerror\fR, with a twist: since there is only one \fBErrorDialog\fR widget, you aren't required to invoke the constructor to create it; it will be created automatically when the first background error occurs. However, in order to configure the \fI\-cleanupcode\fR and \fI\-appendtraceback\fR \&\fBErrorDialog\fR options you must call the constructor and create it manually. .PP The \fBErrorDialog\fR object essentially consists of two subwidgets: a \&\fBDialog\fR widget to display the background error and a \fBText\fR widget for the traceback information. If required, you can invoke various widget methods to customize these subwidgets \- their advertised names are described below. .PP \ \ \ \ \fR\f(CI$mw\fR\fI\fR\->\fBErrorDialog\fR(\-cleanupcode => \fIcode\fR, \-appendtraceback => \fIbool\fR); .PP \&\f(CW$mw\fR is a window reference. .PP \&\fIcode\fR is a CODE reference if special post-background error processing is required (default is undefined). The callback subroutine is called with \f(CW@_\fR having the same arguments that \fBTk::Error\fR was invoked with. .PP \&\fIbool\fR is a boolean indicating whether or not to append successive tracebacks (default is 1, do append). .SS "Advertised ErrorDialog widgets" .IX Subsection "Advertised ErrorDialog widgets" \&\fIerror_dialog\fR is the Dialog widget reference. .PP \&\fItext\fR is the Text widget reference containing the traceback information. .SH BUGS .IX Header "BUGS" If \fBafter\fR or \fBfileevent\fR are not invoked as methods of a widget then perl/Tk is unable to provide a \fR\f(CI$mainwindow\fR\fI\fR argument. To support such code from earlier versions of perl/Tk perl/Tk therefore calls \fBTk::Error\fR with string 'Tk' instead: \&\fBTk\->Tk::Error\e(...\e)\fR. In this case the \fBTk::Error\fR in \fBTk::ErrorDialog\fR and similar implementations cannot "popup" a window as they don't know which display to use. A mechanism to supply \fIthe\fR \fBMainWindow\fR in applications which only have one (a very common case) should be provided. .SH "SEE ALSO" .IX Header "SEE ALSO" Tk::bind Tk::after Tk::fileevent .SH KEYWORDS .IX Header "KEYWORDS" background error, reporting