wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Exception Handling behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Exception Handling behaviour" Watch "Exception Handling behaviour" New topic
Author

Exception Handling behaviour

David Winters Junior
Ranch Hand

Joined: Oct 30, 2007
Posts: 47
Hi All,

I had a few questions regarding exception handling between the different layers in my application i.e client, business, data layers

UrlyBird 1.3.1

Firstly the interface i must implement at the data layer level provided by sun solely throws RecordNotFoundException or DuplicateKeyException however i wish to throw more specific exceptions here. Just wondering how others have implemented their exception handling in their applications and propagating the exception back to the client.

Did others create their own exception classes by subclassing the RuntimeException class in some cases or subclassing the specific Exception
classes provided by the interface provided by Sun perhaps both?

Also did you display a stack trace of the exception to the client at the GUI level or simply display a stack trace in a log file and in the GUI display a specific error message to the client in a dialog box?

Just some general questions here and others have implemented their exception handling in their applications.

Your thoughts would be appreciated.

David
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I wrote my own custom exception class that took a numeric, then as I built the project I added descriptive text strings in a giant switch. I still use it today. The design encapsulates all of my error messages in one place, as well as leverages the exception class for it's traditional role as a programming tool. The type of the class is an Exception,... I used the base class Exception as a design guide, then extended it with the needs I had to do the work that in an exceptional situation.

I keep the display of data to the user at an absolute minimum: "Contact system administrator." Then provide enough recovery information in a log file that reasonable and routine dump forensics are not hampered by users who are not interested in computer science. I intend at some point to extend the utility of the class with a SecureUserException that does some encipherment to a log file, with full-dress key protocol. For the most part, the log just has enough information for a coder to know where to look and is not protected beyond putting enough bulk to discourage people who are not even trying.
[ March 16, 2008: Message edited by: Nicholas Jordan ]

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
David Winters Junior
Ranch Hand

Joined: Oct 30, 2007
Posts: 47
Niclolas,

First of all thanks for your input.

Could you list some sample code here.

For instance the interface by Sun only allows me to throw certain exceptions
so how can i define and throw exceptions which are not allowed by the interface defintion without modifying the interface defintion.

For example the interface provided by sun looks like this:



However say i call the find() method here defined in the class which implements this interface, i have an issue since iw ish to throw exceptions back to the caller which is not a 'RecordNotFoundException'. How would this be possible without modifying the method definition which is not allowed by by interface contract with the implementation class.

If i wish to say throw an IOException from this method i need to declare otherwise the class will not compile..

Thanks,
David
Oguz Ozun
Greenhorn

Joined: May 10, 2007
Posts: 19
Hi,

Think about deriving new exceptions from RuntimeException. These exceptions will be unchecked exceptions and can be added to the definitions of the methods declared in the interface.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
First of all thanks for your input. - Others have helped me.

Could you list some sample code here. Let me pm it or email it, I get too many critical remarks for my coding style on something like this.

For instance the interface by Sun only allows me to throw certain
exceptions so how can i define and throw exceptions which are not allowed
by the interface defintion without modifying the interface defintion


Not really:


Now you can throw eddie back up the call chain.

However say (code) call(s) the find() method here defined in the class which implements this interface, i have an issue since iw ish to throw exceptions back to the caller which is not a 'RecordNotFoundException'. How would this be possible without modifying the method definition which is not allowed by by interface contract with the implementation class.


Try this:



Coder then writes the methods, the interface idea is something I only recently grasped, the interface only describes the call hook. Coder then writes the actual implementation as needed, replete with fixes and all of computer science right there.

If I wish to say throw an IOException from this method I need
to declare otherwise the class will not compile..


Correct, try to catch errors and exceptions before they happen - use the else to handle any reasonably anticipated condition. Use exceptions for exceptional conditions, like cable connectors dirty.

[ March 16, 2008: Message edited by: Nicholas Jordan ]
[ March 17, 2008: Message edited by: Nicholas Jordan ]
David Winters Junior
Ranch Hand

Joined: Oct 30, 2007
Posts: 47
thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Handling behaviour
 
Similar Threads
Passed URLyBird 1.3.2 (400/400)
Waiting for my exam...
Passed!
The perfect solution 155/155 !
Passed SCJD with 137/155