Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design problem with error handling...

 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic