"RuntimeException" don't have to be declare.Meaning, the interface provided by SUN forces you to declare/throw the "Checked" exception. Because of that Interface, you cannot throw any check exception other than what your Interface specifies.
However, RuntimeException (IllegalArgumentException, NullPointerException...Classes inheriting "RuntimeException") don't have to be declare and don't go against your contract.. Without being defined in your contract, you can throw them..
Having that said, it is good practice to define them in your implementation class (and since you are not allowed to modify your interface, you don't put it there..) Try it, create a method, don't declare any "throws". You'll still be able to throw "IllegalArgumentException" because it is a "RuntimeException".
Regards, Alex [ December 05, 2007: Message edited by: Alex Belisle Turcot ]
Alex Belisle Turcot
Joined: Apr 26, 2005
And I guess what William meant is: after catching the runtime exception (from the Object using his Data class), he creates a "normal" Exception (checked.. lets say Implementing "Exception"). Then, he throws this "checked" exception instead of throwing the runtimeException, which would be a little dirty!
Zeng Wei Chu
Joined: Dec 05, 2007
Hi Alex, many thanks for the clear explanation. How about RandomAccessFile operations which can possibly throw IOExceptions within the methods during creation, updating and deleting of records? There are a few possible solutions which I have thought of:
1) Use the declared checked exceptions to wrap it. For example, using the DuplicateKeyException to wrap IOExceptions during record creation process. However doing so does not quite justify the name of the DuplicateKeyException.