Itay

Itay

  • NA
  • 26
  • 0

A very basic question about the way exceptions are integrated with the GUI.

Feb 17 2009 2:28 PM
Hi,
Let say I have a large input form, and in it I have a start date (SD) and an end date (ED) of something. Of course, SD must not be smaller than ED, and of course I take care of it somewhere in my classes (the logic level). [and throw exception if, indeed, SD < ED]
Now the question is how do I tell this (that ED must not be smaller than SD) to my end user?
Should I just check in the GUI whether SD < ED, let the end-user know by a simple message box, but create a very ugly duality of code? (consider that the checking can be MUCH more complicated than SD < ED, this just an example)

Or should I write some static method in the logic class that check (with the needed input) this (whether SD < ED), and use this method in the logic class itself, and in the GUI, but still creating a duality of checking? (this method will be used twice unnecessarily, in the GUI, and once again right after it in the logic class)

Or should I assume the input is okay, but surrounding the pertinent code with a try block, and (in the catch section) expose to the end user, with a message box, the exception, which contains parameters names, terms (etc.) he does not understand, and generally was not intent to him?

Or maybe I should catch the exception and just let the user know that SOMETHING isn't right and pray he will understand what the hell I'm talking about? (imagine a very loaded input form, and a indecipherable message that tells you that something is wrong)

Another option is to create a new kind of exception just for this very specific error (I might create a 1000 different exceptions classes that way).

Or maybe to throw a normal exception, and in the GUI comparing the message string error, to messages I know that might be thrown, and that way to determined what to tell the user.


As I see it, it should be a very basic question, because you're bumping into this situation in almost every application, so I'm quite sure there is some convention about what should be done. Would be glad to hear it :)

Answers (6)