Which is the best way of exception handling?
Answers were Sorted based on User's Feedback
Answer / hari
instead of using try{}catch{} blocks throw an
ApplicationException and make suclass to that class and
extend RuntimeExceptions to ApplicationException class
public void read(String name)throws ApplicationException{
badurl(name);
numberFormate(name);
}
public void badUrl(String name)throws BadUrlException{
}
public void numberFormate(String name) throws
BadNumberException{
}
ApplicationException extends RuntimeException{
}
BadUrlException extends ApplicationException{}
BadNumberException extends ApplicationException{}
Is This Answer Correct ? | 16 Yes | 1 No |
Answer / 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 |
What is synchronization? How it can be achieved?
What is size of int in java?
what is dynamic method dispatch ?
27 Answers Fidelity, MUET, SDSF,
what us Dyna action form?
4 Answers Aithent Technologies,
How do you replace a string in java?
What is a method in programming?
What is the integer of 16?
what is the use of datasource in core java?
Why string objects are immutable in java?
Can we override final method?
How can a class be accessed, If no access modifiers are declared?
What is meant by oops concept in java?