• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Exception?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
rishi
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is checked. If you want to make an unchecked exception, try extending RuntimeException.
 
Rishi Wright
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(){
try{
return play(444);
}catch(Exception e){
System.out.println(e.getMessage());
}catch(FrequencyException fe){
System.out.println(fe.getMessage());
} }
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
rishi
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Throws clause in a method mean - it can throw FrequencyException, not like that it must have throw FrequencyException.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic