ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bhaarat Sharma <bhaara...@gmail.com>
Subject Re: how to do error handling?
Date Thu, 30 Jul 2009 22:42:30 GMT
thanks for your explained answer.
Just to make sure. So you are suggesting that catching the exception at DAO
level is of no use and I should catch the exception at my action class level
( I am using struts2).  So that way, user will only see some generic message
like 'something happened' but message logged in logs will be something
related to DB.

regarding null pointer exception.  This is my sample code in DAO

    public Object[] getIResults(String action) {
        Object[] results = new Object[2];
        HashMap parmMap = new HashMap();
        parmMap.put("action", action);
        List results_list = new ArrayList();
            results_list =
getSqlMapClientTemplate().queryForList("spfile.getReport", parmMap);
        if (!results_list.isEmpty()) {
            results[0] = (List) results_list.get(0);
            results[1] = (List) results_list.get(1);
        return results;

The action class uses the Object[] to show the data to the user.  is this an
OK practice to do this way?

So I will be putting try/catch block in action class when the DAO method is

On Thu, Jul 30, 2009 at 6:29 PM, Nail Uenlue <nail.uenlue@gmail.com> wrote:

> Hello,
> One solution is to put all the code you dont want to execute into the
> try/catch...but i think
> that you're trying to follow a wrong concept ...
> The getSqlMapClientTemplate is from the Spring class DAO support class
> and Spring
> is wrapping the SQLException to a DataAccessException and making them an
> unchecked exception which is 100% correct in my point of view...
> What can you do when you catch  a SQLException from the DB? Does the
> developer
> that catches this exception really know what to do with it? Can he
> recover from such a
> situation at runtime? He cant in 99% of the cases....so dont even
> bother catching those
> exception at DAO level and let them get all the way up to your so
> called Exception Barrier,
> which you can configure at web layer (like the error-page directive in
> the web.xml) and show
> a generic message like "A technical problem occured"...
> Most of the ppl will say that they need more information but a DB
> exception can mostly not be
> translated to a meaningful message to the user...
> And no....your DAO method should never return a null value....why do
> you try to provoke NullPointerExceptions?
> You better let the exception go up as a unchecked exception and handle
> it in your
> Exception barrier..
> On Fri, Jul 31, 2009 at 12:06 AM, Bhaarat Sharma<bhaarat.s@gmail.com>
> wrote:
> > Hi guys,
> > I have a few questions on how to handle errors that are thrown when
> iBatis
> > calls the Stored Procedures.
> > Assuming i have the following code:
> > results_list = getSqlMapClientTemplate().queryForList("spfile.getReport",
> > parmMap);
> > If i have the above code then when error occurs, we see it on the screen
> and
> > it looks very ugly. Also, if the error occurs in above line then code
> after
> > this line is not executed.  I wish to catch the error, put it in the log
> > file and show user a page that something bad has happened.
> > So I changed the above code to:
> >         try {
> >             results_list =
> > getSqlMapClientTemplate().queryForList("spfile.getReport", parmMap);
> >         }
> >         catch (Exception e)
> >         {
> >             log.error(e.getMessage());
> >         }
> > this catches the error fine. BUT the problem is that, since I am catch
> the
> > error, the code after the above call is also being executed.  Which I do
> not
> > want.  If the error occurs in the above call then I don't want any
> further
> > code to get executed.  We are implementing error handling at a later
> stage
> > in the application.  It would have been better if the code written after
> the
> > above call actually checked if something exists in results_list.  But
> that
> > is not the case and it would be a pain to change all the code to suit
> this
> > need now.
> > How can I do this?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org

View raw message