• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Exception handling question

 
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: 24635
56
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: 278
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: 65457
248
  • 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.

 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!