File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please tell me where is the error in this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please tell me where is the error in this program" Watch "Please tell me where is the error in this program" New topic

Please tell me where is the error in this program

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
Henry Wong

Joined: Sep 28, 2004
Posts: 18509

hmmm.... Would it not be a good idea to use javac to report on the error? Or are you looking for something specific?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

Jacob Sonia wrote:ExceptionHierarchy e = new ExceptionHierarchy();

you have declared ExceptionHierarchy as inner class.... so it can't live without the object of the enclosing class.....
try new Exception().new ExceptionHierarchy().....
but this type of coding is a bad idea i suppose............

(Born to Win)
Mo Jay
Ranch Hand

Joined: Feb 16, 2009
Posts: 83
Because you didn't instantiate the outer class MyException first and you tried to instatiate the inner class, you need to do something like this:

By the way, you need to quote your source for this code and say where you got it from.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

Is there any specific error that you are looking to resolve ? If you type in a few words you are likely to get a better response to your question

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
I agree. Here's the link:
subject: Please tell me where is the error in this program
Similar Threads
"Handle or Declare" Rule for Checked Exceptions
Question on "Handle Or Declare" rule for Exceptions - K&B book Page 374 (Exam Watch)
throw exception question
Exceptions doubt
exceptions - handle or declare rule