Forums Register Login

Exception question

+Pie Number of slices to send: Send
Hello,

[URLyBird1.1.1]
I'm currently working on my buissness tier and have a question of handling the RecordNotFoundException.

My Service interface currently contains about the following signatures:



And now? My book method uses the update method from the database which throws RecordNotFoundException.

I can change the signature to throw the RecordNotFoundException to the representation layer. But i think that the RecordNotFoundException is the right exception for the next tier.
Another choice is to handle this exception, but here i don't know what to do. Because i can wrap it into IOException but really don't know if this is good style. And if i doesn't want to wrap it what can i do because i can't eat the exception.

The next problem in this context is the find method where i put in the code for checking if a record is already booked.

Thanks in advance.
alex
+Pie Number of slices to send: Send
Alex

There are a couple of things to consider here

What happens when you have booked the wrong room for a client (in the future) and have to change the record, do you first have to unbook a room?

What happens when a mistake has been made in the past and now has to be changed? (what happens with the 48 hour requirement?)

What happens when you are trying to book a room someone has just booked? (Optimistic Locking scenario)

I kept my app simple and stupid, I'm almost ready to send it in, after all, this was supposed to be a throw away, learning app for junior programmers.

One thing you may want to consider...

In my application, I wrapped all my data access methods in an object wrapper said clases also consisted of an exception for a field, then instead of chaining exceptions I could just check for the presence of a not null exeception in the object and allow my program logic to take it from there, once I got the the presentation layer, if the exception existed, I took care of it in one place with a display exception class.
+Pie Number of slices to send: Send
Hello Thomas,

thanks for your apply. I felt a little bit lost the last two days. *lol

There are a couple of things to consider here

What happens when you have booked the wrong room for a client (in the future) and have to change the record, do you first have to unbook a room?



Yes in future. Now i want to keep this as simple as it is. This means the client can only book a record.

What happens when a mistake has been made in the past and now has to be changed? (what happens with the 48 hour requirement?)



As i said above. An unbooking or changing the customer id i doesn't want to implement in order to keep thinks simple. @Andre: Is it a problem?
The 48h hour rule is also in my buissness layer which means i have a check in both buissness methods find and book to solve the requirement.


What happens when you are trying to book a room someone has just booked? (Optimistic Locking scenario)



As you can see my book method has a boolean return value. In every book operation i check this with an read method from the Data class.

But this isn't really my problem. I try to describe it again.

Consider the following code in my find method:



So and my problem is now that i dont know what to do with the RecordNotFoundException because i doesn't want to change my method signature (i.e. throws RecordNotFoundException). The cause it that if i chain it to the gui layer then i have the problem in this layer. Because i can't prompt the user with a message like "In your find request record 5 has a problem".
The only approach which make sense to me is to throw an RuntimeException.

How would you handle this?

Thanks in advance
alex
+Pie Number of slices to send: Send
Ah, I see what you're getting at.

You can't read a record (with the read method) if its been deleted without throwing a RecordNotFoundException. I had the same quandry, on my first pass I just ate the exception because it most likely was caused (in all cases for me) by a deleted record, on my clean-up pass (several weeks later), I went to the record first (inside a synchronized method) and checked if the record was deleted "checkRecordStatus(int recordNumber, RecordStatusObject)- rso.isDeleted()", if so, I went on to the next record, if not deleted, I read the record into memory and checked against criteria, that way I got around the RecordNotFoundException that the read method throws - Note: checkRecordStatus also has a doesExist (boolean) property as well, for good programming practice.

Also, please note, that I'm an old C and C++ Progammer where memory was at a premium, this approach works, and at the time, it was a best practice, to use random access files and do alot of I/O as opposed to reading everything into memory, however, these days, it seems like programmers like to read everything into memory and iterrate thru it, with an RDBMS you could just run a simple SQL Statment or better yet call a Stored Procedure with at list of arguments, however I digress...

Hope this helps
+Pie Number of slices to send: Send
Hi Alex,

As i said above. An unbooking or changing the customer id i doesn't want to implement in order to keep thinks simple. @Andre: Is it a problem?

Not a problem. Your instructions probably tell you something like you cannot get extra marks for doing anything that is not a requirement. I can't see any requirement for "unbooking" a record (or for the client app to be able to create or delete a record). So you wont get extra marks for handling this. But it is still a design decision not to handle unbooking, so you might want to mention it in your design choices document.

So and my problem is now that i dont know what to do with the RecordNotFoundException because i doesn't want to change my method signature (i.e. throws RecordNotFoundException). The cause it that if i chain it to the gui layer then i have the problem in this layer. Because i can't prompt the user with a message like "In your find request record 5 has a problem".
The only approach which make sense to me is to throw an RuntimeException.

For the find method I see no point in passing the RecordNotFoundException to the client - they were not after a specific record so the exception means nothing to them.

Regards, Andrew
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 610 times.
Similar Threads
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
Database Thread Safety, pls review
MetaData framework
Database Schema / Facade Interface
NX: Trying to get started
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:19:56.