• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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!

 
Marshal
Posts: 24467
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: 257
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: 64493
225
  • 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.

 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!