This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Exception handling question  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am following OCA/OCP practice tests book by Jeanne B and Scott S. I have a qn in Ch8 , qn 49.

The following program compiles and i'm wondering how. The main() does neither declares the checked exception in its signature nor handles it.
In such cases, the program gives compile error. Can someone please provide insight on what i'm missing here. Thanks!

 
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You think that the posted code throws an Exception which is unhandled? Which one do you think that is?
 
Ranch Hand
Posts: 250
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anu Reddy wrote:The main() does neither declares the checked exception in its signature nor handles it.
In such cases, the program gives compile error.


Anu,
As you alluded, the compiler has determined that there are no checked exceptions that must be (further) handled nor declared [including main()].  Thus, the compiler allows compilation.  You likely noticed that none of these method signatures declare exceptions, whereas performBackup() internally handles exceptions and does not elect to pass on any of its exceptions to its caller.

I hope that helps.

Charles
 
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might have seen the correct solution more easily if you had indented your code correctly.
 
Anu Reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:

Anu Reddy wrote:
As you alluded, the compiler has determined that there are no checked exceptions that must be (further) handled nor declared [including main()].  Thus, the compiler allows compilation.  You likely noticed that none of these method signatures declare exceptions, whereas performBackup() internally handles exceptions and does not elect to pass on any of its exceptions to its caller.



Thanks Charles. That makes sense.

 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!