wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception?" Watch "Exception?" New topic


Rishi Wright
Ranch Hand

Joined: Jun 25, 2003
Posts: 46
Hi 'All
I have a small doubt
class FrequencyException extends Exception{

in the above declaration does FrequencyException is a checked exception or is it a runtime exception??
Thank you
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
It is checked. If you want to make an unchecked exception, try extending RuntimeException.

SCJP Tipline, etc.
Rishi Wright
Ranch Hand

Joined: Jun 25, 2003
Posts: 46
but then why the following code is not giving any error
class FrequencyException extends Exception{
public class Note{
public static void main(String argv[]){
System.out.print(n.tune()); }
public int tune(){
return play(444);
}catch(Exception e){
}catch(FrequencyException fe){
} }
public int play(int iFrequency)throws FrequencyException{
return 1; }}

I guess when a method throws a checked exception there MUST be a throw statement in the method.here 'play' is not having any ..
is there any thing wrong in this theory...
thank you
Shabbir Rahman

Joined: Feb 18, 2002
Posts: 18
Throws clause in a method mean - it can throw FrequencyException, not like that it must have throw FrequencyException.

-----------------<br />IBM XML Developer <br />SCJP 1.4
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Shabir: That is true. However, if there is any mention of any checked exception in a method's signature, any call to that method must either catch or declare even though original method does NOT actually throw the declared exception.
Rishi: Your code is actually catching mentioned exception. Therefore, it should compile o.k. However try following code. It will give you error:
I agree. Here's the link: http://aspose.com/file-tools
subject: Exception?
It's not a secret anymore!