This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception?" Watch "Exception?" New topic
Author

Exception?

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
rishi
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(){
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
Shabbir Rahman
Greenhorn

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?
 
Similar Threads
WA #1.....word association
compilation error
counting algorithm
void return type in JSP expression
why JMX can not stop