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
Explain the difference between extends thread vs implements runnable in java?
Is binary a low level language?
What is compareto?
Can we declare a class as abstract without having any abstract method?
What do you mean by collectors in java 8?
How do constructors use this() and super()?
Why is sizeof not a function?
What is use of super keyword?
Difference between static and dynamic class loading.
How is abstraction implemented in java ?
What is the synonym of procedure?
what is thread? What are the high-level thread states? Or what are the states associated in the thread? : Java thread
Is it possible to compare various strings with the help of == operator?
Can a class extend 2 classes in java?
What are the advantages of passing this into a method instead of the current class object itself?