• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practice: logging in 3 tier web application

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a web application presentation layer is done using JSF which talks to business logic layer interfaces ( supplied as jar to JSF application) and business logic access DAO layer jar file to talk to backend.

My question is: Which is the best place ( in which layer) to put "log" statement when handling the exception? Should exception be logged when first caught? or let it propagate to UI layer and there it is logged?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question, and you will find many answers to it. And I wouldn't necessariy argue with any of them. They each have their pros and cons.

The design I like best is using AOP. With AOP I can create a single class that is the ExceptionHandler, and in one method that is a AfterThrows advice, catch the different Exceptions, wrap them into a single ApplicationException, and log the Exception to the logger.

What this means is that there is only one single source for Exception Handling. The client only ever needs to catch one Exception, so making a nice User friendly screen that handles that one exception is easier.

It will make you only need to put try catch code in your business code when you can actually handle that exception at that point in the code. It will also remove any logging code you would have had in your business code, keeping it clean.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic