• 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 program

 
greenhorn
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any body help me to understand the program of K&B book on page 243 . The program is saying to make a method that will take a string & return reverse & also if we will not supply any string ( lenght() == 0 ) then it will throw a new exception .

I tried this much :



thanks in advance .
pooja .
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You did not declared in your code snippet the clas MyException. If your class you exception is a subclass of RuntimeException there will no be any problem, because Runtime exceptions are unchecked. However if MyException is subclass of MyException, but not subclass of RuntimeException you will have either to handle exception in your reverse method or throw it by means of the throws clause up to your main method, where you will have to handle it or add, once again, the trhows clause.

Sample #1: java.lang.RuntimeException (unchecked exception)


Sample #2: With java.lang.Exception (checked exception)


Be careful, because you named your class Exception and that might cause name conflicts. You have to use fully qualified names to refer to the java.lang classes in this case.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic