Re: Not using exceptions only for exceptional conditions
- From: "Rastislav Komara" <moonko@xxxxxxxxx>
- Date: 28 Jun 2006 11:54:15 -0700
villo wrote:
Hi everybody
I always have agreed that exception shouldn't be used for flow control,
nevertheless I have incurred in a situation where breaking this
principle is probably good, for other reasons than design.
The situation is inserting a row in a table, extremely simple stuff. It
happens that the application is basically only doing this and the table
has ~10^7 records, so I have rewritten the application logic, that
would be correctly described as
ARecordObject r=...
if(aDao.find(r)!=null)
aDao.insert(r);
else
aDao.merge(r,anotherRecordObject);
in the form of
if(!aDao.insert(r))
aDao.merge(r,anotherRecordObject);
where insert catches DataIntegrityViolationException and returns true
iff an insert was made.
Now, I see that the first form is better for many reasons, but if the
latter performs faster should I really
bother?
Cheers
Francesco
It is absolutly bad solution. You cannot achieve reasonable performance
using second way. Exceptions are realy realy slow for building stack
trace. If you do not want to use SQL test over DB use other way to
determine which operation is required. I cant recomend DB stored
porcedures. This is hard to write and bound application to special
Database infrastructure lovering portability and cacheing abilities.
.
- Follow-Ups:
- Re: Not using exceptions only for exceptional conditions
- From: Chris Uppal
- Re: Not using exceptions only for exceptional conditions
- References:
- Prev by Date: Encode XML
- Next by Date: Re: dialog on top (current app. only)
- Previous by thread: Re: Not using exceptions only for exceptional conditions
- Next by thread: Re: Not using exceptions only for exceptional conditions
- Index(es):
Relevant Pages
|