• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

handle Exceptions from DB

 
hassan Kalaldeh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i just finished implementing Data class , but before getting started with server design i have some doubts about exceptions handling

in Data class when i encounter unhandled exceptions like IOException for example , i wrap it to RuntimeException , and plan to handle them later , so do you think this is a good idea ??

second question, what is the appropriate way to handle DB exceptions (recordNotFound,Security,DuplicateKey exceptions)? in server side , or i throw them to the client so he can handle them??

i think the client must know that there is something wrong , for example if record doesn't exist while calling update method,he should know the reason .so maybe it's a good idea to handle them in client side,

but on the other hand , i can make update method in server return a boolean value indicate whether update done successfully or not , so recordNotFoundException is handled here in server side !!
im really confused about this

i appreciate Any ideas guys

thanks

opps sorry , i forgot to tell u my assignment is Bodgitt and Scarper
[ December 19, 2005: Message edited by: hassan Kalaldeh ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hassan,

Welcome to JavaRanch and this forum.

in Data class when i encounter unhandled exceptions like IOException for example , i wrap it to RuntimeException , and plan to handle them later , so do you think this is a good idea ??
Sounds good. Most people in this forum recommend creating your own subclass of RuntimeException and wrapping the problem exceptions in that - it means that when you "handle them later" you only have to catch your own subclass of RuntimeException rather than catching all RuntimeExceptions.

second question, what is the appropriate way to handle DB exceptions (recordNotFound,Security,DuplicateKey exceptions)? in server side , or i throw them to the client so he can handle them??

i think the client must know that there is something wrong , for example if record doesn't exist while calling update method,he should know the reason .so maybe it's a good idea to handle them in client side,
Sounds good.

but on the other hand , i can make update method in server return a boolean value indicate whether update done successfully or not , so recordNotFoundException is handled here in server side !!
No - exceptions exist for a reason, and it is probably worth your time to look over the advantages of exceptions.

opps sorry , i forgot to tell u my assignment is Bodgitt and Scarper
Heh. Actually there are very few instances where it makes any difference which assignment a candidate is doing (the 24 hour rule for URLyBird being one example). Certainly none of your questions needed that clarification.

Regards, Andrew
 
hassan kalaldeh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Andrew ,

thanks for replying

as for RunTimeException , i created one of my own .
dude,i read the article from link you gave me ,and as you wrote , exceptions exist for a reason

dude , i really approciate your help

Best Regard
Hassan
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option is to wrap a checked exception in a runtime one so that the client can extract it via Exception#getCause()

Eg,


Hope it helps.
 
hassan kalaldeh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya Alex , that's almost what im going to do but im not sure if i should catch this Exception in the client !!

i mean it's a runTimeException , and when it's thrown , then something is wrong in my system and can not be caught

Best Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic