aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic
Author

Dan's q

Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
Below is taken from Dan's qns. m1() compile error and complain that it did not catch ColorException, I like to know what is the rule that we must adhere here ?
void m1() throws ColorException
{
throw new ColorException();
}
void m2() throws WhiteException
{
throw new WhiteException();
}
public static void main (String[] args) {
White white = new White();
int a,b,d,f;
a = b = d = f = 0;
try
{white.m1();
a++;}
catch (WhiteException e)
{b++;}
try
{
white.m2();
d++;
}
catch (WhiteException e)
{f++;}
System.out.print(a+","+b+","+d+","+f);
}
}


SCJP 2 1.4
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Rule: It is necessary to throw those checked exceptions (or subtypes) that are catched.
Exception: the rule does not apply to Exception.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's q
 
Similar Threads
An Exception question in Dan's mock exam
Exceptions
Q5 from Dan's top exam (2nd)
throws & throw ??
Exception- Doubt Help Please....