It's not a secret anymore!
The moose likes Java in General and the fly likes Best Practices - Exception Handling Mechanism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Best Practices - Exception Handling Mechanism" Watch "Best Practices - Exception Handling Mechanism" New topic

Best Practices - Exception Handling Mechanism

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9967


I have a persistence layer which looks up a JNDI datasource and executes the SQL queries. So in effect, all the persistence methods that I have should handle NamingException and SQLException. Now what would be the best practice to the caller which is usually my middle tier to handle such exceptions? or do I handle them in my persistence layer and throw another generic exception to my service?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
David Newton

Joined: Sep 29, 2008
Posts: 12617

Personally, I'd throw some sort of persistence exception to the next layer up.
I agree. Here's the link:
subject: Best Practices - Exception Handling Mechanism
It's not a secret anymore!