File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Tim Anlauf
Greenhorn

Joined: Oct 11, 2006
Posts: 22
How do you handle IOExcetion's in the Data class ?
MI got serveral solutions but I don't know which I should take...

1. Do nothing --> just printing stackttrace ( surly horrible )
2. throw RemoteExcetion
3. Throw a DatabaseException ( checked or unchecked ? )

I think solution 3 is the best one, but I don't want to change the given interface. Therefore I would use an unchecked Exception.

Does someone has a better solution ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Hello "Tim A..."-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "Tim A...", does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.

Thanks
-Barry

(NR) - search tag


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Tim A...:
How do you handle IOExcetion's in the Data class ?
MI got serveral solutions but I don't know which I should take...

1. Do nothing --> just printing stackttrace ( surly horrible )
2. throw RemoteExcetion
3. Throw a DatabaseException ( checked or unchecked ? )

I think solution 3 is the best one, but I don't want to change the given interface. Therefore I would use an unchecked Exception.

Does someone has a better solution ?


Do your Data methods throw RemoteExceptions?, because this is also a checked exceptions that need to be specified in the method declaration. Your two main options are either wrap the exception in one of the checked exceptions such as RecordNotFoundException or define your own runtime exception and wrap the IOException in that. Both would be considered bad programming practice so pick whichever you think is the lesser of two evils.

Originally I was wrapping IOExceptions in the checked exceptions but I changed to unchecked exceptions later as I felt that it was better to keep the meaning of RecordNotFoundException to solely mean that a record does not exist. Also I think that an IOException should be a rare enough occurance to make throwing a runtime exception acceptable.

The choice is yours...
Mark.


SCJP<br />SCJD
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Thanks for the name update, Tim.
-Barry
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
I cheat (a bit).

My networked database access uses a decorator around my Data class which wraps its operations and throws RemoteException.
The network proxy in turn is set to throw IOExceptions so it's independent of the type of networking used (RemoteException inherits from IOException).

The Data class itself wraps what IOExceptions it gets in unchecked DatabaseExceptions which percolate up through the Remote and its proxy.


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Handling
 
Similar Threads
Questions about method overloading and throwing exceptions...
is HFEJB contradictory?
parsing question
Exception or RuntimeException
adding exceptions to DBAccess