• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Handling behaviour

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
David Winters Junior
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic