aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Exception Chaining , Can it produce unnecessary coupling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Exception Chaining , Can it produce unnecessary coupling?" Watch "Exception Chaining , Can it produce unnecessary coupling?" New topic
Author

Exception Chaining , Can it produce unnecessary coupling?

Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
I notice in Max's book that exception chaining is used to report Database type Exceptions up to the GUI ?
My fear is that chaining exceptions produces unnecessary Coupling between the DB and the GUI, isn't converting a DB type exception to a GUI Exception at one point in the code a better option ?
Any ideas, or am I talking rubbish.
Tony
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hey Tony,
I don't think so, because the relationship is general and not specific to a given type of exception. That is, if you decide to implement it using WebServices or JDBC in the backbend, and you get an exception, the model doesn't need to change. This is one of the big plusses of the Exception Chaining theory.
M


Java Regular Expressions
Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
I'm not sure I understand. Say the underlying DB changed, and another form of exception was recieved by the GUI chained in a RecordNotFoundException.
At all places in the code where the cause was inspected the code would have to change, and at all these places compile time dependencies would exist. So wouldn't it be a better idea to convert all exceptions to GUIExceptions with a simple messages in the GUIController. Hence limiting the changes to one file in one position.
Tony
Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
Oh I see now, in the client we should really only be catching the 'Exception' super class.
Which implies the server must create meaningfull Exception messages, I would think the data class needs to be generic so this must be done in the Data Adapter class.
Tony
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
I completely agree. In my mind, non trivial applications have a middle, and that's where all of this fits in. That is, there are 'system' type exception that might get thrown from your deep backend(say, the DB layer): these would be for file IO, RMI, etc exceptions. These get chained into BusinessExceptions(some of which SUN has already asked you to create: Like DuplicateKeyException: others you might find helpful for your own use). Finally, there are front end GUIExceptions: say FatalGUIException, RecordDoesNotExistGUIException, etc.
In theory, each one of these layers should be separate from the others and correspondingly, their problems should decoupled as well. The theory of exception chaining is that your GUI layer might find it nice to be able to trace an exception all the way to your back end. Or your back end programmers might appreciate knowing exactly what when wrong when the GUI crashed, and may choose to query the GUI guys for a detailed log. IMO, the GUI layer shouldn't be showing these deeper exceptions to the user: shallow error message will do there. But, the gory details should probably be getting logged somewhere, even if it's to the console.
At any rate, the whole point of exception chaining is to allow your client the option of investigating a problem if they want to(or if you need them to). It's not necessary, of course, but I've always found it elegant. It's a bit like being willing to explain what the loss of the nail had to do with the loss of the kingdom, just in case someone cares enough to ask.
M
Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
Right so you'd effectivelly chain the various IOException etc into GUIFatalError Exceptions in the server and pass them onto the client. The message to display on the client would be in the GUIException and the IOException would be chained in the GUIexception, it wouldn't be used but it could be if a problem did arise. And anyway the fatal error would be being logged by the server.
Tony
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
yup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Chaining , Can it produce unnecessary coupling?
 
Similar Threads
Exceptions
NX:Exceptions
Exception handling again
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
Overall Architecture