This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception program

 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • 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 .
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic