/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <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
- 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
- an error or other unusual result of program execution that requires
- interruption of normal program flow and some kind of special
- handling. Java has a rich (and extensible) collection of exception
- classes which represent such conditions.</p><p>jEdit catches exceptions thrown by BeanShell scripts and
- displays them in a dialog box. In addition, the full traceback is
- 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
- more information about the activity log).</p><p>There are two broad categories of errors that will result in
- exceptions:</p><div class="itemizedlist"><ul type="disc"><li><p><span class="emphasis"><em>Interpreter errors</em></span>, which may
- arise from typing mistakes like mismatched brackets or
- missing semicolons, or from BeanShell's failure to find a
- class corresponding to a particular variable.</p><p>Interpreter errors are usually accompanied by the line
- number in the script, along with the cause of the
- error.</p></li><li><p><span class="emphasis"><em>Execution errors</em></span>, which result
- from runtime exceptions thrown by the Java platform when
- macro code is executed.</p><p>Some exceptions thrown by the Java platform can often
- seem cryptic. Nevertheless, examining the contents of the
- activity log may reveals clues as to the cause of the
- 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
- occurred but not where it arose in the script. In those cases, you
- can insert calls that log messages to the activity log in your
- macro. If the logged messages appear when the macro is run, it means
- that up to that point the macro is fine; but if an exception is
- logged first, it means the logging call is located after the cause
- of the error.</p><p>To write a message to the activity log, use the following
- 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
- <b class="fsfunc">log</b>(</code></td><td>int
- </td><td><var class="pdparam">urgency</var>, </td></tr><tr><td> </td><td>Object
- </td><td><var class="pdparam">source</var>, </td></tr><tr><td> </td><td>Object
- </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
- information about the method's parameters.</p><p>The following code sends a typical debugging message to the
- activity log:</p><div class="informalexample"><pre class="programlisting">Log.log(Log.DEBUG, BeanShell.class,
- "counter = " + counter);</pre></div><p>The corresponding activity log entry might read as
- 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
- log, you can use the <code class="function">Macros.message()</code>
- method as a tracing tool. Just insert calls like the following
- in the macro code:</p><pre class="programlisting">Macros.message(view,"tracing");</pre><p>Execution of the macro is halted until the message dialog
- box is closed. When you have finished debugging the macro, you
- should delete or comment out the debugging calls to
- <code class="function">Macros.message()</code> in your final source
- 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>