• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception declaration

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the book Java2:Sun Certified Programmer and Developer

The following compiles just fine:
class TestEx {
public static void main (String [] args) {
badMethod();
}
static void badMethod() { // No need to declare an Error
doStuff();
}
static void doStuff() { //No need to declare an Error
try {
throw new Error();
}
catch(Error me) {
throw me; // We catch it, but then rethrow it
}
}
}
If we were throwing a checked exception rather than Error, then the
doStuff()method would need to declare the exception.

My question:
It is stated that the doStuff()method would need to declare the exception if we were throwing a checked exception rather than Error.
My question:
Would the method badMethod also need to declare the exception if we were throwing a checked exception rather than Error ?
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Would the method badMethod also need to declare the exception if we were throwing a checked exception rather than Error ?


Method badMethod() calls method doStuff(). If doStuff() declares a checked exception, then badMethod() must catch or declare that exception.
[ March 22, 2005: Message edited by: Mike Gershman ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic