Hi to all Ranchers here. Why this code is behaving like this.
Here all are fine except with the IOException. is's saying there should be some code which must throw IOException, why it is being like this where Throwable and Exception class are permitted . [ September 11, 2006: Message edited by: Barry Gaunt ]
It does not compile because IOException is a checked Exception. The catches of Throwable and Exception are special cases in that they have to be allowed to enable unchecked Exceptions (subclasses of RuntimeException) to be caught.
Hey Guys I have also one doubt on this , to my knowledge ClassNotFoundException is also a checked exception , but we can throw it in throws clause of method declaration while not actually throwing it by throw clause from inside method.
Why is such an exception to this exception class ?.
A ClassCastException is an unchecked exception, it extends RuntimeException.
A throws clause indicates only a possibility of an exception being thrown. It does not mean that an exception will always be thrown. If that were the case, most Java APIs would end up throwing exceptions all the time. [ September 12, 2006: Message edited by: Aniket Patil ]
SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Hi Aniket you misread that class that is ClassNotFoundexception not ClassCastException , and ClassNotFoundException is a checked exception,and we can't throw a checked exception in method declaration without actually throwing it from codes inside of the method.
Sorry, i misread the exception you wre talking about.
Do you mean to say that if a method declares that it throws a checked exception in tis signature, and does not throw it from the body, it does not work out.