File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Design problem with error handling... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Design problem with error handling..." Watch "Design problem with error handling..." New topic

Design problem with error handling...

Matthew Alesi
Ranch Hand

Joined: Sep 13, 2006
Posts: 38
I'm working on an important project for school which involves parsing an input data file and processing it into a billing report. My "model" is the bill report generator which formats the report given the processed data, along with associated classes that transform the input data into processed data.

The problem is with error handling. I tried a model-view-controller implementation with a view class representing the GUI and controller classes that perform actions upon GUI events. When I open a data file, the controller directs the model to load the data file and generate the report. However, if there is an error parsing the file, it is propagated all the way up the stack to the controller's method call. I would like to notify the user of where the error occured and such with a dialog box, but the design is getting too confusing for me.

Can someone suggest how I might better implement error handling in my application? This is a very important component of the application, and I don't want it to tarnish an otherwise healthy design, or at least that's how it seems.

Thanks to all!!! This means a lot.

Current CS undergrad
SCJP 5.0
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

Hi Matthew,
Is your application a desktop application or a web based application.
If it is a web based application, you might as well use struts that provides error handling as part of the framework.

apigee, a better way to API!
Matthew Alesi
Ranch Hand

Joined: Sep 13, 2006
Posts: 38
Unfortunately it's a desktop application. I wish error handling were built in because this is proving to be a terrible problem. My grade depends on error handling, and my design goes to waste if it's not provided adequately.

There must be a way for the data file parsing mechanism to communicate to the controller and the view that there was a problem on line x in reading the data, no?

Thanks by the way
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can make a publish-subscribe kind of thing where the model publishes errors to any and all interested subscribers. One of the subscribers could live in the controller and update the view. It honors the MVC dependency model because the subscriber depends on interfaces that belong to the model. I've done one that populates a text area; you could go further to change button states and such so that the user can't do certain things after errors.

The Java library includes Observable and Observer but I find them rather too much for this simple job. This Page describes Pub-Sub about half way down; Ctrl-F search for publish. I made a little abstract "intermediary" that I use all the time. If this path sounds interesting, I can describe it a bit more.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Matthew Alesi
Ranch Hand

Joined: Sep 13, 2006
Posts: 38
This sounds perfect. I just read this after slightly downsizing the structure of my application, and this fits in just how I like it.

Thanks so much for the help!
I agree. Here's the link:
subject: Design problem with error handling...
It's not a secret anymore!