JAVA0166Generic exception caught

Why we will not use Generic exception caught?

what impact it will give ?
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?
CEHJConnect With a Mentor Commented:
It simply doesn't offer any fine-grained control over what is caught and when
objectsConnect With a Mentor Commented:
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.
for_yanConnect With a Mentor Commented:
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 :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.