• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Dan's q

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rule: It is necessary to throw those checked exceptions (or subtypes) that are catched.
Exception: the rule does not apply to Exception.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic