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 7937067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:25:16+00:00 2026-06-03T22:25:16+00:00

I have a question regarding exceptions in a medium-sized Java web application. There is

  • 0

I have a question regarding exceptions in a medium-sized Java web application.
There is a data access layer implemented using JDBC with the logic concentrated mostly in a servlet (the UI is JSP). What is a conventional exceptions’ hierarchy for applications like this?

Should I catch the exceptions on data access layer and rethrow another exception for the whole (e.g. DataAccessException) or simply let the highest level handle them (servlet).

Additionally, I have a connection pool that is called within data access layer and it has its own type of exceptions. Should these exceptions be caught inside data access layer and be rethrown as DataAccessException, or should be handled by higher levels directly?

Would it be a good idea to have a main application exception with the 2 children: LogicException and TechnicalException. Logic will have the subclasses similar to AuthentificationFailedException and so on, while the TechnicalExceptions will be responsible for conveying the information about failures like a data access layer exception, FileNotFound (while it should be) and so on?

Thank you!

  • 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-03T22:25:18+00:00Added an answer on June 3, 2026 at 10:25 pm

    Generally I wrap lower level exceptions with higher level, more meaningful exceptions. This is usually more work, but gives you decoupling between layers.

    Imagine I am writing a configuration subsystem that happens to read from database. If I don’t wrap, I would have something like:

    public String getConfigurationProperty(String name) throws SQLException {
        // Try to read from my configuration table
    }
    

    If I do the wrapping, I would have

    public String getConfigurationProperty(String name) throws ConfigurationException {
        try {
            // Try to read from my configuration table 
        } catch (SQLException ex) {
            ConfigurationException wrapper = // Some subclass of ConfigurationException that wraps ex
            throw wrapper;
        }
    }
    

    This is definitely more work. The advantage is that if at a later time I want to change my configuration backend to, say, a file based one, without wrappers my method would become

    public String getConfigurationProperty(String name) throws IOException {
        // Try to read from my configuration file
    }
    

    And then I would have to change all my client code to deal with IOExceptions instead of SQLExceptions. If you do the wrapping, you just need to change the backend, because your client code was already written with ConfigurationExceptions and its subclasses in mind. Note that this is independent of wether you use checked or unchecked exceptions: if you want to do exception handling, you almost always need to know at least some approximation for the type of exceptions you want to handle.

    Now, this is what I tend to do. There is people that thinks that most exceptions cannot be properly handled anyway and all these wrapping is nonsense most of the time.

    public String getConfigurationProperty(String name) throws ConfigurationException {
        try {
            // Try to read from my configuration file 
        } catch (IOException ex) {
            ConfigurationException wrapper = // Some subclass of ConfigurationException that wraps ex
            throw wrapper;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding using LightSpeed in a MVC3 Web application. I am
I have a question regarding logging in a Java application. I want to log
I have a question regarding the integration of business objects developed using Linq To
I have a question regarding memory deallocation and exceptions. when I use delete to
I have a question regarding formatting of data cells in the delphi DBGrid. The
I am working on a java web application and I have a few questions
I have a question regarding Spring Web Flow with JSF: How can I teach
I have a question regarding ResultSet objects in Java and recursion. I was working
I have a question regarding handling errors in a J2EE application. Our current application
I have a question regarding exception handling. Consider following Java code snippet. try{ //code

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.