• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If no records found is that really an Exception?

 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!
In my model I currently throw a NoMatchingDataException which I then catch in the controller and display an error message but I am unhappy about this as surely its very possible that there may be no flights listed for a particular origin/destination combination.
However this mechanism works perfectly to prevent the model trying to broadcast its search results (which are null) to the gui and to signal the controller to tell the gui to display a message that no result could be found.
Am I justified in using an Exception in this way?
Kindest regards Sam
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:

In my model I currently throw a NoMatchingDataException
Am I justified in using an Exception in this way?

IMHO, throwing an exception for a "0 records found" is toooooooooo much. 1. the exception should help the user for an alternative like "Illegal searchcriteria" or something which the user needs to act on.
2. the exception can be thrown if the user is going to lose some vital information
please refere to Peter's previous article on how to handle Exception, it will be under some Connection Factory topic.
all the best
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
Hi everyone!
In my model I currently throw a NoMatchingDataException which I then catch in the controller and display an error message but I am unhappy about this as surely its very possible that there may be no flights listed for a particular origin/destination combination.
However this mechanism works perfectly to prevent the model trying to broadcast its search results (which are null) to the gui and to signal the controller to tell the gui to display a message that no result could be found.
Am I justified in using an Exception in this way?
Kindest regards Sam

No matching records is a normal situation, and it is not a good practice to deal with normal situations in a catch block. (Catch blocks require a good bit of overhead)
Reserve use of exceptions for exceptional situations.
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aadhi and BJ thanks for the confirmation - have changed method call to pass back no of records found and if 0 gui now displays an informational message to the user.
Thanks for the input
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic