1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Java: When not to use Exceptions.

Discussion in 'Java' started by Sanskruti, May 6, 2007.

  1. Sanskruti

    Sanskruti New Member

    The exception handling mechanism is a cleaner way to impose check upon the conditions which may lead to errors. But you should not be carried away by it and start using exception handling anywhere and everywhere you want. Exceptions must be carefully planned and implemented. The following cases suggest when you should avoid the usage of exceptions.

    If you can avoid an erroneous condition without exception handling, easily with a minimum coding, you should prefer to use that than the exception. Though exception handling seems to be very convenient to the programmer, it takes up a lot of time of the processor. For instance, the ArrayIndexOutOfBoundsException is used to detect whether the upper bound of the array has been crossed. If we devote a little more time in testing our code and assure that this erroneous condition would never arise in our program, it will prove to be a more beneficial alternative.

    Sometimes exception handling is taken very lightly and is used as a jumping mechanism forgetting the purpose for which exceptions are used. This is not a good programming practice; and it in fact creates confusion and makes code difficult to maintain.

    Also, if a piece of code is throwing some exception it must be handled properly. Catching the exception just for the sake of catching and leaving the catch block empty does not really help. Remember that the exceptions are the warnings given in advance for the upcoming possible errors which should be handled seriously.
     

Share This Page