• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about page 319 (Java OCA 8 Programmer I Study Guide)

 
Cedric Georges
Greenhorn
Posts: 18
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the last example of page 319 (the example which doesn't compile).

I tried the following code, which works fine:
NetBeans give me the following output:
Am I missign something?

Thank you for your help!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cedric Georges wrote:Am I missign something?

Yes, you are!

You are missing a (custom) checked exception. Don't forget that with Exception you can catch runtime exceptions as well. That's why the code compiles. But that's not what the study guide provides as an example. It uses a checked NoMoreCarrotsException and that's the difference with your code. So if you are too lazy to create a custom checked exception (like NoMoreCarrotsException) try changing all Exception occurences in your code with IOException and see what happens.

Hope it helps!
Kind regards,
Roel

PS. In Java we don't use underscores in package and class names.
 
Cedric Georges
Greenhorn
Posts: 18
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply Roel!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic