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 the epoch date?
What variables are stored in stack?
Can a lock be acquired on a class?
What is the relationship between clipping and repainting under awt?
What is math exp in java?
What are some alternatives to inheritance?
How will you compute size of a structure?
What languages are pass by reference?
Can we assign integer value to char in java?
Explain about join() method?
Difference between abstract class and Interfaces?
7 Answers CTS, iFlex, PA Consulting, Sai Softech, Value Chain,
What is purpose of keyword void?