Ans:
Exception is nothing but a situation where program terminate abnormally.
Ans:
It is a technique through which program can be protected from abnormal
termination.
Ans:
Exception are of 2 types
1) Checked Exception
2) Unchecked Exception
Ans:
Checked Exception-The Exception which generate at the time of compilation &
handle at that time is known as Checked Exception. Except Runtime & its child
class all other exception are checked exception. The Exception which generate at
the time of execution is known as Unchecked Exception.RuntimeException and its
child class are treated as unchecked exception.
Ans:
There are 5 keyword provide by java they are:
1) try
2) catch
3) Throw
4) Throws
5) finally
Ans:
Try block contain the Exception generate code.
Ans:
Difference between catch and finally is:
Catch generally contain exception handle code where finally always contain
unreachable code & closing of connection.The execution of catch is optional
where the execution of finally is compulsory.
Ans:
Diff. b/w throw& throws keyword is :
Throw keyword generate the userdefined or predefined exception explicitly.
Where throws keyword transfer the exception of caller of that function.
Ans:
Ans:
1. If the super class method does not declare an exception ,subclass overridden
method cannot declare the checked exception but it can declare unchecked
exception.
2. If the super class method declares an exception , subclass overridden method
can declare same, sub class exception or no exception but cannot declare
parent exception.
Ans:
If we have null value in the variable ,performing any operation by variable occurs
an NullPointerException.
Ans:
If we divide any number by zero ,there occurs an ArithmeticException.
Ans:
If you are inserting any value in the wrong index , it would result
ArrayIndexOutOfBoundExceptipon.
14. How to handle exception by super class & specify the restriction?
Ans:
Exception is the super class of all exception in java, so this class can handle any
type of exception generate by java program. Only restriction is Exception catch
block should be last catch block among exception hierarchy.
15. What things should be kept in mind while creating your own exceptions in Java?
Ans:
16. Does it matter in what order catch statements for FileNotFoundException and
IOException are written?
Ans:
Before handle by super class I,e IOException, handle with sub class
FileNotFoundEXception. Otherwise it is an error in java.
Ans:
This exception is thrown when there has been made an attempt to store the wrong type
of object into an array of objects.
Ans:
Yes possible because these are the unchecked exception.
19. Is there any way to skip Finally block of exception even if some exception occurs
in the exception block?
Ans:
If user exit from application by System.exit(0) method.
20. Who is the super class of all the Exception in java & How it handle Exception?
Ans:
Exception is the superclass of all the exception in java so it can handle any kind
of exception generate by the program.
Ans:
Try block should be followed by a catch or finally block other wise an error.
Ans:
Try block compulsory execute when program already executed.
Ans:
Catch block contain exception handle code.
Ans:
Multiple catch is allowed but maximum one catch can be execute at a single time.
25. Is execution of catch is optional?
Ans:
Yes execution of catch is purely optional.
Ans:
PrintStackTrace is a predefined method present in throwable class which always
display name of Exception, why Exception occure , and line no of Exception.
Ans:
Finally block is a very powerful block in java which execute when try will execute.
Ans:
Maximum one finally allow for a single try.
Ans:
Overridden method only throws that exception which throws by superclass
method.
Ans:
Throwable.
31. Which concept use to convert runtime error into user friendly message by java
programmer?
Ans:
Exception Handling.
Ans:
An Exception is first thrown from the top of the stack & if it is not caught ,it drop
down the call stack to the previous method ,if not caught there ,the exception not
drop down to the previous method and so on they are untile they reach the very
bottom of the call stack Which is called Exception propagation.
Ans:
If you are creating your own Exception that is known as Custom Exception – user
defined exception.
Ans:
1) using an object of java.lang.Exception class.
2) using public void PrintStack method.
3) using public ssStringgetMessage method.
36. State the rules for handling exception with overriding method?
Ans:
1) If the super class method does not declare an exception ,subclass overridden
method cannot declare the checked exception but it can declare unchecked
exception.
2) If the super class method declares an exception , subclass overridden method
can declare same, sub class exception or no exception but cannot declare
parent exception.