| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>6.8. Error Handling</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.0"><link rel="home" href="index.html" title="Apache Click"><link rel="up" href="ch06.html" title="Chapter 6. Best Practices"><link rel="prev" href="ch06s07.html" title="6.7. Logging"><link rel="next" href="ch06s09.html" title="6.9. Performance"></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">6.8. Error Handling</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s07.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Best Practices</th><td width="20%" align="right"> <a accesskey="n" href="ch06s09.html">Next</a></td></tr></table><hr></div><div class="sect1" title="6.8. Error Handling"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="error-handling"></a>6.8. Error Handling</h2></div></div></div><p> In Click unhandled errors are directed to the |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/ErrorPage.html" target="_blank">ErrorPage</a> |
| for display. If applications require additional error handling they can create |
| and register a custom error page in <code class="filename">WEB-INF/click.xml</code>. |
| For example: |
| </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><pages</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">package</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"com.mycorp.page"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">autobinding</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"annotation"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">/></span> |
| <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><page</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">path</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"click/error.htm"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">classname</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"com.mycorp.page.ErrorPage"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">/></span> |
| <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></pages></span></pre><p>Generally applications handle transactional errors using service layer code |
| or via a servlet |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/Filter.html" target="_blank">Filter</a> |
| and would not need to include error handling logic in an error page. |
| </p><p>Potential uses for a custom error page include custom logging. For example |
| if an application requires unhandled errors to be logged to an application |
| log (rather than System.out) then a custom |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/ErrorPage.html" target="_blank">ErrorPage</a> |
| could be configured. An example <code class="classname">ErrorPage</code> error logging |
| page is provided below: |
| </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">package</span> com.mycorp.page.ErrorPage; |
| .. |
| |
| <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> ErrorPage <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> org.apache.click.util.ErrorPage { |
| |
| <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">void</span> onDestroy() { |
| Logger.getLogger(getClass()).error(getError()); |
| } |
| }</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06s07.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.7. Logging </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.9. Performance</td></tr></table></div></body></html> |