PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/www/tags/NOV_07_2009/htdocs/users-guide/macro-tips-debugging.html

#
HTML | 42 lines | 42 code | 0 blank | 0 comment | 0 complexity | 32a264d1ea008f63bfa73d0d3d3682e4 MD5 | raw file
 1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Debugging Macros</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="macro-tips.html" title="Chapter 15. Macro Tips and Techniques"><link rel="prev" href="macro-tips-BeanShell.html" title="Advanced BeanShell Techniques"><link rel="next" href="bsh-commands.html" title="Chapter 16. BeanShell Commands"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Debugging Macros</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="macro-tips-BeanShell.html">Prev</a> </td><th width="60%" align="center">Chapter 15. Macro Tips and Techniques</th><td width="20%" align="right"> <a accesskey="n" href="bsh-commands.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="macro-tips-debugging"></a>Debugging Macros</h2></div></div></div><p>Here are a few techniques that can prove helpful in debugging
 2        macros.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="macro-tips-debugging-exceptions"></a>Identifying Exceptions</h3></div></div></div><p>An <em class="glossterm">exception</em> is a condition reflecting
 3            an error or other unusual result of program execution that requires
 4            interruption of normal program flow and some kind of special
 5            handling. Java has a rich (and extensible) collection of exception
 6            classes which represent such conditions.</p><p>jEdit catches exceptions thrown by BeanShell scripts and
 7            displays them in a dialog box. In addition, the full traceback is
 8            written to the activity log (see <a class="xref" href="activity-log.html" title="Appendix B. The Activity Log">Appendix B, <i>The Activity Log</i></a> for
 9            more information about the activity log).</p><p>There are two broad categories of errors that will result in
10            exceptions:</p><div class="itemizedlist"><ul type="disc"><li><p><span class="emphasis"><em>Interpreter errors</em></span>, which may
11                    arise from typing mistakes like mismatched brackets or
12                    missing semicolons, or from BeanShell's failure to find a
13                    class corresponding to a particular variable.</p><p>Interpreter errors are usually accompanied by the line
14                    number in the script, along with the cause of the
15                    error.</p></li><li><p><span class="emphasis"><em>Execution errors</em></span>, which result
16                    from runtime exceptions thrown by the Java platform when
17                    macro code is executed.</p><p>Some exceptions thrown by the Java platform can often
18                    seem cryptic. Nevertheless, examining the contents of the
19                    activity log may reveals clues as to the cause of the
20                    error.</p></li></ul></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="macro-tips-debugging-log"></a>Using the Activity Log as a Tracing Tool</h3></div></div></div><p>Sometimes exception tracebacks will say what kind of error
21            occurred but not where it arose in the script. In those cases, you
22            can insert calls that log messages to the activity log in your
23            macro. If the logged messages appear when the macro is run, it means
24            that up to that point the macro is fine; but if an exception is
25            logged first, it means the logging call is located after the cause
26            of the error.</p><p>To write a message to the activity log, use the following
27            method of the <a class="ulink" href="../api/org/gjt/sp/util/Log.html" target="_top">Log</a> class:</p><div class="itemizedlist"><ul type="disc"><li><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr><td><code class="funcdef">public static void
28                            <b class="fsfunc">log</b>(</code></td><td>int
29                             </td><td><var class="pdparam">urgency</var>, </td></tr><tr><td> </td><td>Object
30                             </td><td><var class="pdparam">source</var>, </td></tr><tr><td> </td><td>Object
31                             </td><td><var class="pdparam">message</var><code>)</code>;</td></tr></table></div></li></ul></div><p>See the documentation for the <a class="ulink" href="../api/org/gjt/sp/util/Log.html" target="_top">Log</a> class for
32            information about the method's parameters.</p><p>The following code sends a typical debugging message to the
33            activity log:</p><div class="informalexample"><pre class="programlisting">Log.log(Log.DEBUG, BeanShell.class,
34    "counter = " + counter);</pre></div><p>The corresponding activity log entry might read as
35            follows:</p><div class="informalexample"><pre class="programlisting">[debug] BeanShell: counter = 15</pre></div><div class="sidebar"><p class="title"><b>Using message dialog boxes as a tracing tool</b></p><p>If you would prefer not having to deal with the activity
36                log, you can use the <code class="function">Macros.message()</code>
37                method as a tracing tool. Just insert calls like the following
38                in the macro code:</p><pre class="programlisting">Macros.message(view,"tracing");</pre><p>Execution of the macro is halted until the message dialog
39                box is closed. When you have finished debugging the macro, you
40                should delete or comment out the debugging calls to
41                <code class="function">Macros.message()</code> in your final source
42                code.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="macro-tips-BeanShell.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="macro-tips.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bsh-commands.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Advanced BeanShell Techniques </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 16. BeanShell Commands</td></tr></table></div></body></html>