Which is the best way of exception handling?

Answer Posted / sudhir dhumal

First best way is use built-in exception classes wherever possible, you don't need to create your custom exception class to represent every scenario, so try to use existing exception classes

Second best way of handling exception is creating custom exception for specific scenario by extending our class with Exception class.

Consider the following example...

public class BookSearchException extends Exception {
public BookSearchException(String message) {
super(message);
}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.

839


What is the difference between method and means?

574


What are the steps involved to create a bean?

685


What flag up means?

607


What are the loops in java?

528






What are the restrictions imposed by a Security Manager on Applets?.

2073


What is r in java?

595


What is meant by final class?

570


Name component subclasses that support painting in java programming?

642


what are different ways in which a thread can enter the waiting state? : Java thread

498


What is the parse method in java?

576


Can we force garbage collector to run ?

574


How would you dynamically allocate memory to an array?

599


How an object is serialized in java?

536


How are java objects passed to a method and what are native methods?

603