aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exception program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exception program" Watch "exception program" New topic
Author

exception program

pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
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 .


:d
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
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
 
subject: exception program
 
Similar Threads
Propogating Exceptions - Exercise5.3 in K&B
about exception
Propagating and Catching an exception problem
Exercise on Propagating Exceptions. Am I missing something?
[Easy] Shift String