| Author |
Constructors and Exceptions
|
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
Please confirm my assumption. If a constructor throws a checked exception (say IOException), then ANY subclass of this class must have an EXPLICIT constructor which throws this exception or a superclass of the exception, correct? But when dealing with methods, the overriding method must not throw any new or broader checked exception, so it's basically the complete opposite to constructors? Thanks in advanced.
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
[Marzo]: If a constructor throws a checked exception (say IOException), then ANY subclass of this class must have an EXPLICIT constructor which throws this exception or a superclass of the exception, correct? Not quite. If there is more than one constructor in the superclass, and at least one constructor does not throw the checked exception, then a subclass constructor may avoid the checked exception as well as long as it invokes the correct super constructor. E.g. so it's basically the complete opposite to constructors? Yes, in terms of what checked exceptions may be thrown.
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: Constructors and Exceptions
|
|
|