Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter understanding exceptions and logging in a J2EE environment
    text
    copied!<p>I'm trying to better understand exception handling and logging in a <code>j2ee</code> environment to refactor some legacy code (we use <code>log4j</code> for our logging mechanism). Most of our current code does something like the code below on the business tier, however, I'd like to switch over to unchecked exceptions and just ignore them unless it makes sense to handle them somewhere:</p> <pre><code>try { doSomething(); } catch (MyException e) { log.error("Exception:", e); throw e; } </code></pre> <p>After the exception is thrown in the business tier, it is then propagated up to the presentation tier, which again catches the exception and usually wraps it in a <code>PortletException</code> or <code>ServletException</code> and throws it again. Then, it is handled by a Spring handler which shows a 'friendly' message to the user. I'd ultimately like to only handle exceptions for which we want to show a specific error message, and just ignore everything else.</p> <p><strong>Questions:</strong></p> <ol> <li>Is it necessary to log exceptions in the business tier? If not, do I need to log exceptions at all (especially unchecked ones)?</li> <li>What happens to uncaught exceptions that are not logged using log4j? (If they're still printed in the console, what's the purpose of log4j?)</li> </ol> <p>I am confused as to how the process works...</p> <p>Thanks.</p> <p><strong>EDIT:</strong> If an exception occurs in an outside library (Spring, Hibernate, etc), is it assumed that these exceptions will be printed out using whatever logging mechanism is being used? In that case, I guess that I would only need to log the exceptions that my code throws... or am I way off base here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload