• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Exceptions Okay for program to catch?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky Scott Selikoff
SE 8 Programmer I Study Guide

page 305: Types of exceptions table 6.1:
Type:  Error : Okay for program to catch :  NO

In the Review questions of the Exceptions chapter it was allowed.

If it is Not OK to catch (according to table 6.1)
why is it allowed in the chapter review questions ?

Please help,
confused about interpretation.

 
Ranch Hand
Posts: 586
6
jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not read the book but I have a question to you. Are you clear about exception and error?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Edward Sixth wrote: If it is Not OK to catch (according to table 6.1)
why is it allowed in the chapter review questions ?


It's really a subtle difference. It's allowed to catch an Error, so you could write the following code and the compiler will be happy with it (it will not give you a compiler error)But because it is allowed, it doesn't mean it's a good thing to do. So in real world applications you'll rarely see an Error being caught. And the reason is very simple: it's very unlikely that the application can recover after a thrown Error . For example if an OutOfMemoryError is thrown, the JVM will have tried to run the garbage collector a few times to be certain to have freed as much memory as possible, but if it's still not enough there's nothing your application can do.

So although it is allowed to handle or declare Errors (you won't get a compiler error if you try to do so), it is not ok (recommended) for a program to catch.

Hope it helps!
Kind regards,
Roel
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

I understand what you are saying, but table 6.1 contains a mistake in the context of taking this exam. It is, in fact, OK for a program to catch an error. This mistake should be listed in Errata. However, a parenthetical comment or a note below the table that says catching an error in real development isn't recommended would be helpful.

Chuck
 
author & internet detective
Posts: 39789
797
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles Cavin wrote:Hi Roel,

I understand what you are saying, but table 6.1 contains a mistake in the context of taking this exam. It is, in fact, OK for a program to catch an error. This mistake should be listed in Errata. However, a parenthetical comment or a note below the table that says catching an error in real development isn't recommended would be helpful.

Chuck


This is subtle, but the book is right. It's not ok to catch an an error. if the exam asks you if it is ok/appropriate, the answer is no.

On the other hand, the exam may ask you if code that performs that bad practice compiles or how it behaves. And you are expected to know that too!
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!