ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kezerashvili, Denis" <Denis.Kezerashv...@gs.com>
Subject RE: How to custom database exception?
Date Mon, 31 Dec 2007 17:19:37 GMT
Well, from the original message it sounded to me that the problem was
that some obscure SQLException was thrown and "someone with an
impressive title had seen that exception in production". I assume the
exception was logged and it was not clear what it was to that particular
person. The code was added to "convert" that obscure SQLException into
something meaningful. 
If there was a need to act on that exception (and seeing Chris' reply
there was such a need), I am not sure why the conversion needed to
happen at all, why not just catch an SQLException at the place where it
needs to be acted upon and maybe log the issue at that point as well
with a clear message of what happened.

But I think we are getting off the original topic here. 


-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
Of Larry Meadors
Sent: Monday, December 31, 2007 11:58 AM
To: user-java@ibatis.apache.org
Subject: Re: How to custom database exception?

I'd have to agree with Chris.

If your code "won't be broken unless you are relying on that generated
custom exception to be caught and acted upon", then what's the point
of the custom exception?

It sounds to me like you are saying "It'll work, unless it doesn't, so
don't rely on it working." :-)

Seems like extra work (cost) without added functionality (value). I
know my clients don't like that. ;-)


On Dec 31, 2007 9:29 AM, Chris Lamey <clamey@localmatters.com> wrote:
> That's exactly why it was a hack and is easily broken.
>  Like I said before, a test in the catch looked for a specific string
in the
> SQLException's message and threw a new custom exception that was
> appropriately elsewhere.
>  -----Original Message-----
>  From: Kezerashvili, Denis [mailto:Denis.Kezerashvili@gs.com]
>  Sent: Mon 12/31/2007 6:47 AM
>  To: user-java@ibatis.apache.org
>  Subject: RE: How to custom database exception?
>  You code won't be broken unless you are relying on that generated
>  exception to be caught and acted upon. If the Oracle exception has
>  changed for some reason it will just fall through your custom
>  piece of code. I am guessing you are rethrowing other types of
>  exceptions that you did not write special handling for, so you should
>  fine:)
>  Denis
>  ________________________________
>          From: Chris Lamey [mailto:clamey@localmatters.com]
>          Sent: Saturday, December 29, 2007 9:47 AM
>          To: "<user-java"@ibatis.apache.org
>          Subject: RE: How to custom database exception?
>          Hello, my name is Chris and I've committed this most
>  hack.
>          Many years ago when I was young and easily led down the dark
>  side, a requirement came down from on high that required a custom
>  message for a specific Oracle error message.  The project was already
>  through the development and test phase.  Someone with an impressive
>  title had seen that exception in production and it had to be taken
>  of.  The requirement came at me late at night and had to be
>  immediately - there was no time to think!
>          So in the catch block of SQLException, I tested for the
>  Oracle error ID in the exception mesage.  If it was there, I threw
>  of our custom exceptions that produced the desired effect in the
>  application.
>          At the time, I commented that code as something that was a
>  and had to be changed.  I promised myself I would go back and fix it.
>  But alas, this did not come to pass and that code is still running.
>          It was to easy to get done at the time...it haunts me to this
>  day.
>          If they switch DBs, even versions of Oracle, that code is
>  broken.  Trying to map DB specific error codes to an Exception
>  is madness.  Instead, it is better to test for those conditions and
>  constraints up front and not to let it be an error condition.
>          It's also good to read Josh Bloch's Effective Java for the
>  section on Exception handling.  He makes a pretty strong case for not
>  using custom Exceptions as what amounts to return codes for commonly
>  expected cases.
>          Cheers,
>          Chris
>          -----Original Message-----
>          From: larry.meadors@gmail.com on behalf of Larry Meadors
>          Sent: Sat 12/29/2007 6:35 AM
>          To: user-java@ibatis.apache.org
>          Subject: Re: How to custom database exception?
>          That's a SQL/JDBC problem, really - a unique constraint
>  give
>          you much in terms of customizing the message. I guess if you
>  wanted
>          to, you could look at the message and try to map it to a
>          message...but iBATIS isn't going to do that for you. It would
>          infeasible to map any database error message to custom
>  exceptions.
>          Larry
>          On Dec 28, 2007 10:59 PM, yuan gogo <gogoyuan@gmail.com>
>          > Hi, all.
>          >     I'm new to iBatis, and wonder how to get custom data
>  exception in the
>          > web application.
>          >
>          >    Say, I have a database table Users (id, username,
>  password), the username
>          > is UNIQUE.
>          >    While insert new user data with a duplicated username ,
>  data exception
>          > will be thrown from jdbc indicate constraint conflict on
>  datafileds.
>          > But I personally think throw a custom exception like
>          > UsernameExistedException will be a better way for other
>  to log or
>          > notify user.
>          >
>          >    How can I do it?
>          >
>          > Ps : I use Tapestry 5 + spring 2.5M + iBatis 2 + postgresql
>  8.3 beta +
>          > tomcat 6.0.14 for evaluation.
>          >
>          > Thanks!
>          >
>          > gogoyuan [_at_] gmail.com
>          >

View raw message