• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

handle Exceptions from DB

 
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 ]
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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
 
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
 
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
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic