The moose likes Developer Certification (SCJD/OCMJD) and the fly likes throwing exceptions question (weird quirk) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "throwing exceptions question (weird quirk)" Watch "throwing exceptions question (weird quirk)" New topic

throwing exceptions question (weird quirk)

Rob Zidsen

Joined: Jul 07, 2003
Posts: 16
In my testing, I notice a little quirk, and I don't really know how to explain it. This is the problem:
In my read() method, I check for the record's validity and throw a RecordNotFoundException if the valid flag is not 00:

This seemed to work fine in my testing.
THEN I added an catch-all catch statement to read():

For some reason now, this catch statement catches the RecordNotFoundException I'm trying to throw to the calling class!! The calling class no longer catches RecordNotFoundException because of this, obviously. Of course I took out this catch statement and all is well again, but I still don't understand why it's doing this. Can someone enlighten me?
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Rob,
It depends where you put your catch all block. If it is in the read method, it right. It will not be thrown to the client, because it is catched in your read on the server:
public Record read(recNo) {
try {
// some code throwing RecordNotFoundException
if (...) throw new RecordNotFoundException(...);

} catch (Exception ex) {
// RecordNotFound will be catched here and, of course, not thrown
// to the client


If I understand you incorrectly, could you specify in more detail where is your RecordNotFound exception is thrown and where is your "catch all Exceptions" block.
I agree. Here's the link:
subject: throwing exceptions question (weird quirk)
It's not a secret anymore!