• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exceptions

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

This code is from Dan Chisholm mock exam. I have changed the original question and compiled this. It is giving the following error message.
Please explain this error.








Thanks in advance,
Mubeen
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exception is a result of the fact that e1 is the parent class of e3. The first catch statement (e1) will catch all e3 exceptions thrown. The compiler is smart enough to know that any e3 exception thrown will never make it outside of the e1 block.

Try switching the order of the catch blocks and it should compile -- i.e. catch e3 and then later catch e1.
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the explanation Dave. It woks as you have said.

Now i am more confused with the following code.

Here Level3Exception is child of Level2Exception.(Correct?). This code compiles and runs. I am confused with this.

My Question what is the difference between this code and previous one?.

=====================



Thanks in advance
Mubeen.
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When working these types of problems, it can be helpful to drwaw pictures. e2 and e3 are peers in this case:

Here e3 doe not inherit from e2.
[ February 14, 2005: Message edited by: Dave Winn ]
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because of "extends", i thought it will be like this.

Now how e2 and e3 are at the same level? Please explain.




Exception
-----------
e1
----------
e2
---------
e3


Thanks in advance,
Mubeen.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mubeen
I have posted an answer to this forum, where you also posted this question. please don't post your question twice.
Renaud
 
Renaud Richardet
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave

I completely agree with your first post. However, i don't get it when you say:

Here e3 doe not inherit from e2.

on your second post. I believe the heritage diagram from Mubeen is right.

Cheers, Renaud
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic