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
Can you sort a string in java?
What is null data type?
Is overriding possible in java?
How do you sort arrays in java?
What is keyword auto for?
Is minecraft 1.15 out?
Explain what pure virtual function is?
How hashmap works in java?
What is the memory leak in java?
What is a functional interface?
What will be the default values of all the elements of an array defined as an instance variable?
Why vector is used in java?
What is an immutable object?
Can we create an object of static class in java?
What is Mutex (Mutual Exclusion Object) ?