JAVA0166Generic exception caught

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

Why we will not use Generic exception caught?

what impact it will give ?
    LVL 86

    Accepted Solution

    It simply doesn't offer any fine-grained control over what is caught and when
    LVL 92

    Assisted Solution

    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

    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    abstract class with all non abstract mentods 6 58
    EvenOdd challenge 10 68
    java constructor error 8 65
    wordsWithout 49 64
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now