error.html
来自「perl教程」· HTML 代码 · 共 169 行
HTML
169 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Tk::Error - Method invoked to process background errors</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>Tk::Error - Method invoked to process background errors</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#tk__errordialog">Tk::ErrorDialog</a></li>
<ul>
<li><a href="#advertised_errordialog_widgets">Advertised ErrorDialog widgets</a></li>
</ul>
<li><a href="#bugs">BUGS</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#keywords">KEYWORDS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tk::Error - Method invoked to process background errors</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p>Customization:</p>
<pre>
<span class="keyword">require</span> <span class="variable">Tk::ErrorDialog</span><span class="operator">;</span>
</pre>
<p>or</p>
<pre>
<span class="keyword">sub</span><span class="variable"> Tk::Error
</span><span class="operator">{</span>
<span class="keyword">my</span> <span class="operator">(</span><span class="variable">$widget</span><span class="operator">,</span><span class="variable">$error</span><span class="operator">,</span><span class="variable">@locations</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@_</span><span class="operator">;</span>
<span class="operator">...</span>
</pre>
<pre>
}</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <strong>Tk::Error</strong> 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 <strong>Tk::Error</strong>
method (e.g. as a perl sub) if they wish to handle background
errors in some other manner.</p>
<p>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 <a href="../../lib/Tk/callbacks.html">callback</a> specified with a
<a href="../../lib/Tk/bind.html">bind</a> or a <a href="../../lib/Tk/after.html">after</a>
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.</p>
<p>When Tk detects a background error, it saves information about the
error and invokes the <strong>Tk::Error</strong> method later when Tk is idle.</p>
<p><strong>Tk::Error</strong> is invoked by perl/Tk as if by the perl code:</p>
<p> <em>$mainwindow</em>-><strong>Tk::Error</strong>(<em>"error message"</em>, <em>location ...</em>);</p>
<p><em>$mainwindow</em> is the <strong>MainWindow</strong> associated with widget which
detected the error, <em>"error message"</em> is a string describing the error
that has been detected, <em>location</em> is a list of one or more "locations"
which describe the call sequence at the point the error was detected.</p>
<p>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.</p>
<p>Tk will ignore any result returned by the <strong>Tk::Error</strong> method.
If another error occurs within the <strong>Tk::Error</strong> method
(for example if it calls <strong>die</strong>) then Tk reports this error
itself by writing a message to stderr (this is to avoid infinite loops
due to any bugs in <strong>Tk::Error</strong>).</p>
<p>If several background errors accumulate before <strong>Tk::Error</strong>
is invoked to process them, <strong>Tk::Error</strong> will be invoked once
for each error, in the order they occurred.
However, if <strong>Tk::Error</strong> calls <strong>Tk->break</strong>, then
any remaining errors are skipped without calling <strong>Tk::Error</strong>.</p>
<p>The <strong>Tk</strong> module includes a default <strong>Tk::Error</strong> subroutine
that simply reports the error on stderr.</p>
<p>
</p>
<hr />
<h1><a name="tk__errordialog">Tk::ErrorDialog</a></h1>
<p>An alternate definition is provided via:</p>
<p> <code>require Tk::ErrorDialog;</code></p>
<p>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.</p>
<p>This is an OO implementation of the Tcl/Tk command <strong>bgerror</strong>, with a
twist: since there is only one <strong>ErrorDialog</strong> 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 <em>-cleanupcode</em> and <em>-appendtraceback</em>
<strong>ErrorDialog</strong> options you must call the constructor and create it
manually.</p>
<p>The <strong>ErrorDialog</strong> object essentially consists of two subwidgets: a
<strong>Dialog</strong> widget to display the background error and a <strong>Text</strong> widget
for the traceback information. If required, you can invoke various
widget methods to customize these subwidgets - their advertised names
are described below.</p>
<p> <em>$mw</em>-><strong>ErrorDialog</strong>(-cleanupcode => <em>code</em>, -appendtraceback => <em>bool</em>);</p>
<p>$mw is a window reference.</p>
<p><em>code</em> is a CODE reference if special post-background error
processing is required (default is undefined). The callback subroutine
is called with @_ having the same arguments that <strong>Tk::Error</strong> was
invoked with.</p>
<p><em>bool</em> is a boolean indicating whether or not to append successive
tracebacks (default is 1, do append).</p>
<p>
</p>
<h2><a name="advertised_errordialog_widgets">Advertised ErrorDialog widgets</a></h2>
<p><em>error_dialog</em> is the Dialog widget reference.</p>
<p><em>text</em> is the Text widget reference containing the traceback information.</p>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>If <strong>after</strong> or <strong>fileevent</strong> are not invoked as methods of a widget
then perl/Tk is unable to provide a <em>$mainwindow</em> argument.
To support such code from earlier versions of perl/Tk
perl/Tk therefore calls <strong>Tk::Error</strong> with string 'Tk' instead:
<strong>Tk->Tk::Error\(...\)</strong>.
In this case the <strong>Tk::Error</strong> in <strong>Tk::ErrorDialog</strong> and similar
implementations cannot "popup" a window as they don't know which display
to use. A mechanism to supply <em>the</em> <strong>MainWindow</strong> in applications
which only have one (a very common case) should be provided.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Tk/bind.html">Tk::bind</a>
<a href="../../lib/Tk/after.html">Tk::after</a>
<a href="../../lib/Tk/fileevent.html">Tk::fileevent</a></p>
<p>
</p>
<hr />
<h1><a name="keywords">KEYWORDS</a></h1>
<p>background error, reporting</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?