• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Question about create()

 
Lim YH
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I just think of when create a new record , need to validate the data and if the data is invlid, how can deal with this case.
I need create a new Exception and wrap it in the exception DuplicateKeyException???
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lim,
Welcome to JavaRanch and this forum !
I just think of when create a new record , need to validate the data and if the data is invlid, how can deal with this case. I need create a new Exception and wrap it in the exception DuplicateKeyException???

Wouldn't it be better to throw some IllegalArgumentException (RuntimeException) in that case ? Or a class of your own extending IllegalArgumentException ? It wouldn't force you to change the method signature (you must not BTW), neither use an existing checked exception whose purpose is different.
Cheers,
Phil.
 
Lim YH
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Phil,
thanks for your answer, a runtime exception is right.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just my 2 cents worth, given its a new record why can't you validate
all the data before ever getting to the database side. You could
validate the data in you controller if you are using an MVC pattern
for your gui. The only exception you would have to handle at the
back end of the process would be a duplicate key exception which may
be in your interface provided by sun already.
 
Lim YH
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bill
I think when I put the validate logic on client side, this mean the client side must know all fields of record and each field means what, I think it's not suitable for expanding. So I just do the validation on server side
Lim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic