> -----Original Message-----
> From: Janne Mattila [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, September 08, 2004 11:57 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Proper place for validation
> 
> 

<snip>

> 
> I am fully aware that this is probably not the "accepted" way 
> of doing this. 
> All advice seems to say to create specific exception classes for your 
> applications exceptions. I have just never really understood 
> what benefit it 
> _really_ brings. It would be nice to "see the light" though, 
> so I would not 
> have to be such a heretic anymore.... :)

Creating an exception for each business rule allows you to remove any dependancy 
between presentation and other layers.  Putting an english error message in an 
exception destiend for a non-english reader makes no sense.   One answer is to use 
Java's built in i18n facilities, except that now you can't change your message 
resource without changing your business/dao tier, that doesn't sit well with trying to 
achieve complete separation between layers.  However, if I throw an exception that 
indicates the rule broken, or the general issue, then my view layer can map the 
exception to the message.


> 
> 
> >From: "Jim Barrows" <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >Subject: RE: Proper place for validation
> >Date: Wed, 8 Sep 2004 08:52:05 -0700
> >
> >
> >
> > > -----Original Message-----
> > > From: Janne Mattila [mailto:[EMAIL PROTECTED]
> > > Sent: Wednesday, September 08, 2004 3:49 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: Proper place for validation
> > >
> > >
> > > Hmm, not a lot of comments on this. I guess there is a
> > > consensus on the
> > > matter (that, or no-one really gives a damn).
> > >
> > > A quick followup on this; how could I achieve both
> > >
> > > a) decoupling of my business classes from Struts
> > > b) internationalization
> > >
> > > if I validate in my business class?
> > >
> > > 1)
> > > if (alreadyExists(email)) {
> > >    throw new MyAppException("E-mail address already exists");
> > >
> > > achieves a) but not b), and
> > >
> > > 2)
> > > if (alreadyExists(email)) {
> > >    throw new MyAppException("errors.email.duplicate");
> >
> >Simple, you throw EmailAlreadyExists( email), and catch 
> that, or use the 
> >exception handling ability of struts to give an appropriate 
> error message 
> >to the user.  For system level stuff (ie DB is missing etc) 
> you inlcude a 
> >cause, but don't necessarily show it to the user.
> 
> _________________________________________________________________
> Add photos to your messages with MSN 8. Get 2 months FREE*. 
> http://join.msn.com/?page=features/featuredemail
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to