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

Is string is a data type in java?

798


What is the transient keyword?

1261


What is the purpose of an interface?

769


Can we sort array in java?

708


What is the purpose of using the java bean?

794


why an outer class cannot be declared as private?

3900


what r advatages of websphere? & how to deploy?

1844


Is null an object in java?

774


What kind of variables a class can consist of?

840


What is the use of inner class?

754


What is private static class in java?

742


Can memory leak in java?

786


What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

760


What java ide should I use?

753


Why do we use predicate in java?

796