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


Please Help Members By Posting Answers For Below Questions

why Interface used?

529


What is bean? Where it can be used?

595


Why is it called boolean?

516


Which is illegal identifier in java?

583


Can you override a final method?

571






What does singleton mean in java?

505


What is keyword and identifier?

631


What is the difference between interface & abstract class?

553


Why we do exception handling in java and how many types of exceptions are there?

539


How do you convert boolean to boolean?

515


What does sprintf mean?

524


What is an eror in java?

552


What is the equal sign?

553


What is classname class in java?

526


Can we split string with in java?

524