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 |
From the two, which would be easier to write: synchronization code for ten threads or two threads?
Is there any difference between synchronized methods and synchronized statements?
What is the use of default method in interface in java? Explain
What does this () mean in java?
What is high level language in computer?
What is percentage in java?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
explain the concept of inheritance with an example?
What is bytecode verifier?
Explain the difference between a Thread and a Process.
where lives in jvm
What is an iterator java?