Pawel Pawlowicz wrote:I have a Record class which is used in business layer. It holds a single record from a database.
It has several setter methods like setCustomerId(String id). Those methods may throw IllegalArgumentException.
May I assume that I will always get proper values from DB class?
I could catch IllegalArgumentException but that would mean catching unchecked exceptions and this should be avoided.
I could check the argument before passing it to Record but that would mean doubling the same code (checking inside and outside Record class).
What approach do you prefer?
I always assume the data provided in the db file are valid.
It is up to you to check if the data is valid when you are reading the db file. If you read a negative integer for a room occupancy number , for example, then throw an exception and move on to read the next record. When the exception is thrown, don't create a Record instance.
Again, for simplicity, you don't need to worry about invalid data in the file.
If the room you are trying to reserve has been occupied, then show a warning box to let the user know the room cannot be reserved.