In: Computer Science
Exception handling
All Exceptions that can be thrown must descend from this Java class:
The getMessage( ) method is inherited from this class?
What are the two broad catagories of Exceptions in Java?
If an Exception is not a checked exception it must extend what class?
What is the difference between a checked Exception and an unchecked Exception?
What are the two options a programmer has when writing code that may cause a checked Exception to be thrown? Can a try block contain code that would cause more than one type of Exception to possibly be thrown?
Is it true that a try block can only be followed by ONE catch block?
What is the purpose of the finally block?
When is the code in the finally block executed?
What happens when a try block throws an Exception object? Is an Exception the same thing as a syntax or logic error?
ANSWER:-
-> getMessage() is a method of Throwable class which is inherited by every exception class like ArithmeticException,NullpointerException etc.
-> There are two categories of exceptions
1.checked exception
2.unchecked exception
-> If an exception is not checked exception then it must extend RuntimeException class.
->Difference between checked and unchecked exceptions:-
1. Checked Exception:- The classes which extend Throwable class except RuntimeException,those exceptions are known as checked exceptions. These exceptions checked at compile time.
2.Unchecked Exceptions:- The classes which extend RuntimeException class ,those are known as unchecked exceptions. These are checked at runtime.
->A programmer has two options. Those are:
1. Using throws keyword ,a programmer can throw an exception
2. try-catch block
A try block can contain more than one exception that can be thrown by catch blocks.
-> A try bock can contain multiple catch blocks.
try{
//code
}catch(//exception parameter){
//code
}
catch(//exception parameter){
//code
}
catch(//exception parameter){
//code
}
-> finally block executes irrespective of the exception that means even if exception occurs or not finally block must excecute.
-> When an exception is thrown it checks whether catch block regarding that exception is there or not. if it is there, the code in the catch block executes. if it is not there,then it shows default error message.
THANK YOU!!!!!