• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply Roel!
reply
    Bookmark Topic Watch Topic
  • New Topic