• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is not enough seats available an excpetion?

 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I seem to be struggling to decide when an event is an exception or when it is something that prevents the requested action taking place but should be condidered a normal and possible part of program flow.
Sun's guidlines describe an exception thus:

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.

So by my estimation that would make the case of there not being enough seats in the database to cover the number requested an event that would not disrupt the normal flow of instructions as the user can simply be informed that there are not enough seats and the display updated to reflect the actual number available.
Am I right in this estimation?
Many thanks Sam
 
lev grevnin
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So wait a second. Your last paragraph was confusing a bit. You should not throw any exceptions if the client tried to make a booking for more seats than there are available. This is an improper use of exceptions. Use exceptions for things like: not being able to connect to database, the database file is corrupted, etc. Any user input should be checked and an appropriate action taken. It's similar to an "if" statement: do you always throw an exception every time the condition is false? No. You just take an appropriate action. Same thing with the user input in your situation.
So exceptions are for unexpected conditions.
hope it helped.
-lev
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
Hi all
So by my estimation that would make the case of there not being enough seats in the database to cover the number requested an event that would not disrupt the normal flow of instructions as the user can simply be informed that there are not enough seats and the display updated to reflect the actual number available.
Am I right in this estimation?
Many thanks Sam

Yes, you are right. That is part of the normal flow, and is not a place for an exception.
-BJ
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Regarding throwing a exception when there are no seats available and the sun guidelines, my opinion is that we should check the user input against the available seats shown in the JTable, but this works with a local database.
Now imagine a remote database where your JTable shows 5 seats available but other user as reserved 4 seats and you want to reserve 2 seats! In my opinion this disrupts the normal flow and can be considered a exception.
I have created 2 exceptions for the reservation of seats and these exceptions are only throw in a remote environment by the reservation class and messages are then show to the user informing why the reservation as not been made.
The reservation is requested only if we have enough seats available showing in the JTable, so these exceptions are never throw in local mode, but in a remote mode they can happen due to what I've said in the begining.
Miguel
[ March 03, 2003: Message edited by: Miguel Roque ]
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that guys. Much appreciated.
I'm not sure I want to start distinguishing between local and remote connections in my processing though as surely once the connection is made the type of connection should be transparent to the user otherwise it will make for difficult to maintain and breakable code?
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic