Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:16:33+00:00 2026-06-02T09:16:33+00:00

I have a medium-size Java Web-application using Log4J as logging-framework. Right now i am

  • 0

I have a medium-size Java Web-application using Log4J as logging-framework.
Right now i am going through my Exception handling and Logging to make my application more robust.
It is running on Tomcat 6, with spring, hibernate and Struts2 as frameworks.

What I would like to do is to log EVERY UNHANDLED exception that happens in the application. So that i can log them, make log4j send me an email, and then see where i am missing try-catch blocks. And finally modify my code accordingly.

Cause right now all the unhandled exceptions is printed direct to the screen, and my users usally do not bother to copy me the exceptions.

I know i can read tomcat-logs, but i would like to have them handled by log4j so that i can get an email on every such exception.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:16:36+00:00Added an answer on June 2, 2026 at 9:16 am

    With Struts2, you can define global exception mappings for specific Exception types. If you define one for java.lang.Exception it acts as a catch-all for any exception not mapped elsewhere:

    <global-exception-mappings>
      <exception-mapping exception="com.example.MyException result="myError" />
      <exception-mapping exception="java.lang.Exception" result="error" />
    </global-exception-mappings>
    
    <global-results>
      <result name="myError">/myError.jsp</result>
      <result name="error">/error.jsp</result>
    </global-results>
    

    In your error JSPs (*), you can then log them with log4j and give your users a nice “Something went wrong” error page without confronting them with confusing stacktraces.

    (*) better: An error action where you can log the exception and only then let Struts render a JSP where you tell the user that something went wrong. No need to clutter JSPs with logging code.

    About modifying all your code:

    Don’t blindly add catch blocks all over your code — if some piece of code can’t handle an exception, just let it propagate (adding a throws clause on the method signature if necessaty). At certain levels in the stack, consider wrapping the thrown Exception and adding some information to help identifying the cause and rethrow it:

     catch (IllegalArgumentException ex) {
        // Always pass the original exception along, never just the message.
        // It's much easier to find the root cause that way.
        throw new UpdateException("Failed to parse foo object: " + foo, ex);
     }
    

    Also, resist the temptation of emtpy catch blocks. They swallow the exception and you may never find out that something or what might be going wrong in your application. Log all exceptions unless you’re very sure you’ll never be interested in them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a medium size Java Web Application with Struts as MVC framework
I have a medium size Java file. Everytime I make a change to one
We have a medium sized .js file that we include in our web framework
I have a medium sized application that runs as a .net web-service which I
I have a medium sized application written in c++ using Qt. I wanted to
I am planning on writing a medium size web application that will be XML
I have a medium size legacy php application with almost no javascript integration. I've
I have a small- to medium-size project that I am doing for my software
I have a string that is HTML encoded: '''&lt;img class=&quot;size-medium wp-image-113&quot;\ style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;\
I have two medium-sized web applications that I'm merging into one. They are both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.