⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session6.html

📁 j2eePDF格式的电子书
💻 HTML
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Handling Exceptions</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="Session5.html" />    <link rel="Next" href="BMP.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="Session5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="BMP.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <blockquote><a name="wp80322"> </a><h2 class="pHeading1">Handling Exceptions</h2><a name="wp80323"> </a><p class="pBody">The exceptions thrown by enterprise beans fall into two categories: system and application.</p><a name="wp80324"> </a><p class="pBody">A <span style="font-style: italic">system exception</span> indicates a problem with the services that support an application. Examples of these problems include the following: a database connection cannot be obtained, a SQL insert fails because the database is full, or a <code class="cCode">lookup</code> method cannot find the desired object. If your enterprise bean encounters a system-level problem, it should throw a <code class="cCode">javax.ejb.EJBException</code>. The container will wrap the <code class="cCode">EJBException</code> in a <code class="cCode">RemoteException</code>, which it passes back to the client. Because the <code class="cCode">EJBException</code> is a subclass of the <code class="cCode">RuntimeException</code>, you do not have to specify it in the <code class="cCode">throws</code> clause of the method declaration. If a system exception is thrown, the EJB container might destroy the bean instance. Therefore, a system exception cannot be handled by the bean's client program; it requires intervention by a system administrator.</p><a name="wp80326"> </a><p class="pBody">An <span style="font-style: italic">application exception</span> signals an error in the business logic of an enterprise bean. There are two types of application exceptions: customized and predefined. A customized exception is one that you've coded yourself, such as the <code class="cCode">InsufficentBalanceException</code> thrown by the <code class="cCode">debit</code> business method of the <code class="cCode">SavingsAccountEJB</code> example. The <code class="cCode">javax.ejb</code> package includes several predefined exceptions that are designed to handle common problems. For example, an <code class="cCode">ejbCreate</code> method should throw a <code class="cCode">CreateException</code> to indicate an invalid input parameter. When an enterprise bean throws an application exception, the container does not wrap it in another exception. The client should be able to handle any application exception it receives.</p><a name="wp80329"> </a><p class="pBody">If a system exception occurs within a transaction, the EJB container rolls back the transaction. However, if an application exception is thrown within a transaction, the container does not roll back the transaction.</p><a name="wp80334"> </a><p class="pBody"><a  href="Session6.html#wp80342">Table 20-1</a> summarizes the exceptions of the <code class="cCode">javax.ejb</code> package. All of these exceptions are application exceptions, except for the <code class="cCode">NoSuchEntityException</code> and the <code class="cCode">EJBException</code>, which are system exceptions.</p><div align="left"><table border="1" summary="Exceptions" id="wp80342">  <caption><a name="wp80342"> </a><div class="pTableTitle">Table 20-1   Exceptions&nbsp;</div></caption>  <tr align="center">    <th><a name="wp80348"> </a><div class="pCellHeading">Method Name</div></th>    <th><a name="wp80350"> </a><div class="pCellHeading">Exception It Throws</div></th>    <th><a name="wp80352"> </a><div class="pCellHeading">Reason for Throwing</div></th></tr>  <tr align="left">    <td><a name="wp80354"> </a><div class="pCellBody"><code class="cCode">ejbCreate</code></div></td>    <td><a name="wp80356"> </a><div class="pCellBody"><code class="cCode">CreateException</code></div></td>    <td><a name="wp80358"> </a><div class="pCellBody">An input parameter is invalid.</div></td></tr>  <tr align="left">    <td><a name="wp80360"> </a><div class="pCellBody"><code class="cCode">ejbFindByPrimaryKey</code></div><a name="wp80361"> </a><div class="pCellBody"><code class="cCode">(</code>and other finder methods that return a single object<code class="cCode">)</code></div></td>    <td><a name="wp80363"> </a><div class="pCellBody"><code class="cCode">ObjectNotFoundException</code></div><a name="wp80364"> </a><div class="pCellBody"><code class="cCode">(</code>subclass of <code class="cCode">FinderException)</code></div></td>    <td><a name="wp80366"> </a><div class="pCellBody">The database row for the requested entity bean cannot be found.</div></td></tr>  <tr align="left">    <td><a name="wp80368"> </a><div class="pCellBody"><code class="cCode">ejbRemove</code></div></td>    <td><a name="wp80370"> </a><div class="pCellBody"><code class="cCode">RemoveException</code></div></td>    <td><a name="wp80372"> </a><div class="pCellBody">The entity bean's row cannot be deleted from the database.</div></td></tr>  <tr align="left">    <td><a name="wp80374"> </a><div class="pCellBody"><code class="cCode">ejbLoad</code></div></td>    <td><a name="wp80376"> </a><div class="pCellBody"><code class="cCode">NoSuchEntityException</code></div></td>    <td><a name="wp80378"> </a><div class="pCellBody">The database row to be loaded into the entity bean cannot be found.</div></td></tr>  <tr align="left">    <td><a name="wp80380"> </a><div class="pCellBody"><code class="cCode">ejbStore</code></div></td>    <td><a name="wp80382"> </a><div class="pCellBody"><code class="cCode">NoSuchEntityException</code></div></td>    <td><a name="wp80384"> </a><div class="pCellBody">The database row to be updated cannot be found. </div></td></tr>  <tr align="left">    <td><a name="wp80386"> </a><div class="pCellBody">(all methods<code class="cCode">)</code></div></td>    <td><a name="wp80388"> </a><div class="pCellBody"><code class="cCode">EJBException</code></div></td>    <td><a name="wp80390"> </a><div class="pCellBody">A system problem has been encountered.</div></td></tr></table></div><p class="pBody"></p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><a name="wp78998"> </a></pre></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="Session5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="BMP.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -