File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "throwing exceptions question (weird quirk)" Watch "throwing exceptions question (weird quirk)" New topic
Author

throwing exceptions question (weird quirk)

Rob Zidsen
Greenhorn

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) {
ex.printStackTrace();
// 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.
Regards,
Vlad
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: throwing exceptions question (weird quirk)
 
Similar Threads
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
URLyBird Throwing exceptions
Javadoc: What to document if one exception is caught and another is throwed?
About the read and find method
assert false or RuntimeException() for unreachable code