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

  • Home
  • SEARCH
  • 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 1018051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:47:55+00:00 2026-05-16T10:47:55+00:00

I am trying to come up with a manageable way to handle exceptions in

  • 0

I am trying to come up with a manageable way to handle exceptions in a DAO. Typically a method in my DAO looks like this:

public ArrayList fetchColors (String id)
{
    //call iBatis SqlMapClient
    //put results in a list
    //return list
}

If an error happens in the above code then everything is written to server.log and on the front page I show custom error screen. However, I want to avoid to put the stacktrace to server.log but instead write it to my_app.log (I’m using log4j).

So I’m planning to transform above method to following:

public ArrayList fetchColors (String id) throws SqlException
{
    try {
    //call iBatis SqlMapClient
    //put results in a list
    }
    catch (SqlException e)
    {
      logger.log (e);
      throws e;
    }
    //return list
}

Questions:

  • Is this the best way to approach the problem?
  • I have lot of methods in the DAO and doing the above for each method will be a PITA..Is there an easier way to do this so same thing applies to all the methods in a DAO?
  • 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-05-16T10:47:56+00:00Added an answer on May 16, 2026 at 10:47 am

    A ‘callback‘ solution in order to handle exception and log in one place:

    interface CallBack{
        void invoke();
    }
    

    Define a skeleton method like:

    //Skeleton to handle exception and log in one place 
    public void doBusiness(CallBack callBack)  throws SqlException{
        try{
            callBack.invoke();
        }catch(SqlExceptione){
            logger.log (e);
            throws e;
        }
    }
    

    Call it like:

    public ArrayList fetchColors (String id) throws SqlException{
        doBusiness(new CallBack(){
    
            public void invoke() {
                   //call iBatis SqlMapClient
                   //put results in a list     
                }        
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with the best way to handle user subscription and
What I'm trying to come up is something that's expressed like this: var result
Trying to come up with the logic and the standard way to do this.
Trying to come up with a more compact way of expressing this conditional in
I'm trying to come up with a way combine two arrays that have different
I am trying to come up with a method to differentiate between form being
I'm trying come up with the best method of synchronizing particular rows of 2
I am trying to come up with the best way to implement SQL Data
I'm trying come up with a method to determine how long after the user
I've been trying to come up with a way to declare array constants in

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.