Steve Taiwan<br />SCJP 1.2, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, OCP 8i DBA, SCEA
Originally posted by Steve Taiwan:
I got B&S.
To implement Interface DBAccess, RecordNotFoundException, SecurityException
and DuplicateKeyException Classes must be created since they are unimplemented.
My Question is
Because they are declared in throws clause of methods,
should they all extend Exception class and become checked Exception??
Or
In previous threads, some argue SecurityException and DuplicateKeyException
should extend RuntimeException. But I didn't read any reason for this.
Thank you for reading my thread.
===================================================================
Definition of RuntimeException:
A method is not required to declare in its throws clause
any subclasses of RuntimeException that might be thrown
during the execution of the method but not caught.
Definition of "Exception" class:
The class Exception and its subclasses are a form of
Throwable that indicates conditions that a reasonable
application might want to catch.
[ September 14, 2004: Message edited by: Steve Taiwan ]
[ September 14, 2004: Message edited by: Steve Taiwan ]
Steve Taiwan<br />SCJP 1.2, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, OCP 8i DBA, SCEA
Originally posted by Steve Taiwan:
Dear Petter.
Before I post, I have read threads about IOException and SecurityException, I choose:
1. IOException: I wrap it inside RecordNotFoundException.
reasone: "can't read file" means "can't get any record"
2. SecurityException: I go with making a different class from java.lang.SecurityException.
reason: The purpose of SecurityException is completely different from
java.lang.SecurityException. I prefer making a new class.
================================================
I prefer making my own exception classes for these 3 exception.
And you suggest:
1. RecordNotFoundException: extend "Exception" for checed excpetion.
2. SecurityException: extend "Exception" for checed excpetion.
=============================================
My question is:
1. What is your opinion about DuplicateKeyException?
2. What are your reasons for checked or runtime exception?
Thank you, petter.
Steve Taiwan<br />SCJP 1.2, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, OCP 8i DBA, SCEA
peter define a DataException as a runtime exception and use that to wrap IOException. This way I don't need to modify the interface and RuntimeException is usually indicative of a fatal error.
Originally posted by HSUAN CHEN:
Hi peter
i have a question about your post, hope you can help me ,thank you
that will implements be..
if i made some mistake please tell me
public synchronized String[] read(int recNo) throws RecordNotFoundException
{
try {
// file access
}
catch (FileNotFoundException ex) {throws new DataExcetion()}
catch (IOException ex) {throws new DataExcetion()}
}
peter
My changes are:
- different variable names need for exceptions
- throw not throws
- use exception chaining
- follow Sun coding convention
Don't get me started about those stupid light bulbs. |