JAVA0166Generic exception caught

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-05-11

Why we will not use Generic exception caught?

what impact it will give ?
LVL 86

Accepted Solution

CEHJ earned 668 total points
ID: 35691182
It simply doesn't offer any fine-grained control over what is caught and when
LVL 92

Assisted Solution

objects earned 668 total points
ID: 35691326
you should only catch generic exceptions if you are trying to stop exceptions from escaping a block of code.
When catching generic exceptions you may accidentally catch exception that you did not anticipate.
LVL 47

Assisted Solution

for_yan earned 664 total points
ID: 35692152
Nevertheless, in doing some quick code - not for Java certification but for real life -  it is very convenient
to catch just any Exception. You then print exception.toString()
and printStackTrace exception.printStackTrace() - and you know everything you need to know.
Well, of course you should stick to the rules, but it is not necessary always to be dogmatic.

What is absolutely detrimentantal - even in the quickest and dirtiest code writing
is just catch exception silently like that ....catch(Exception ex) {}
That caused me in the very beinnings of my java days several times to spend literally hours on
debugging very small programs. Even if you are debugging while driving (never do that!),
and the program has three lines, you don't want to do that :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question