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
What are the different types of sorting in java?
What is sortedmap interface?
How do I enable java in safari?
What is hashset in java?
What are the concepts of 'OOPS'?
What is overloading and overriding in java?
How can we make a class singleton?
What restrictions are placed on method overriding in java programming?
What is an example of procedure?
Can we use both this () and super () in a constructor?
Which are different kinds of source code?
What does system.gc() and runtime.gc() methods do?
How do I find and replace in word?
What is set in java?
How does linkedlist work in java?