Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception- Doubt Help Please.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception- Doubt Help Please...." Watch "Exception- Doubt Help Please...." New topic

Exception- Doubt Help Please....

deepu Bhalotia
Ranch Hand

Joined: Apr 19, 2005
Posts: 39
class ColorException extends Exception {}

class WhiteException extends ColorException {}

class White
void m1() throws ColorException {throw new WhiteException();}
void m2() throws WhiteException {}

public static void main (String[] args)
White white = new White();
int a,b,d,f; a = b = d = f = 0;

catch (ColorException e)

catch (WhiteException e)

I think the Answer willbe 0101 But the Given answer is 0,1,1,0.

Can anybody explain please.....

With Regards,
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
Why do you think m2 is required to throw a WhiteException?

The method m2 doesn't actually throw the WhiteException, so it just returns normally. The throws keyword only says "Look out! I could throw this Exception if things go wrong!" It doesn't mean that the Exception WILL be thrown, only that it CAN be.
I agree. Here's the link:
subject: Exception- Doubt Help Please....
It's not a secret anymore!