Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Exception Handling FAQs


Untitled Document

Q37.  Explain the process of creating the customized Exception.
Ans.   Creating customized Exception:
Class TooYoungException extends RuntimeException{
  TooYoungExcetpion(String desc){
                Super(desc);
                }
}
Class TooOldException extends RuntimeException
{
                TooOldException(String desc){
super(desc);
                }
}
Class custExcepiton{
                Public static void main(String[] args){
Int age=Integer.parseInt(args[0]);
If(age>60)
{
Throw new TooYoungException(“Please wait some more time, definitely you will get best match”);
                }
                Else if(age<18)
                {
Throw new TooOldException(“Your age is already crossed of marriage, no chance to getting marriage”);
                }
                Else
                {
                                System.out.println(“Congratulation! You will get match details soon by your email”);
                }
}
               

Q38. Explain control flow in try, catch, finally.
Ans.       Try{
                Statement1;
                Statement2;
Statement3;
}
Catch(X e){
Statement4;
}
Finally{
Statement5;
}
Statement6;
Case1:
If there is no Exception then output is
Statement1
Statement2
Statement3
Statement5
Statement6
Normal termination
Case2:
If an exception raised at statement2 and corresponding catch block has matched then output is
Statement1
Statement4
Statement5
Statement5
Normal termination
Case3:
An exception raised at statement2 and corresponding catch has not matched then output is
Statement1
Statement5
Abnormal termination
Case4:
An exception occurs at statement4 it always Abnormal termination but before that finally block will be executed and output is
Statement1
Statement2
Statement5
Abnormal termination
Case5:
If an exception raised at statement5 or statement6, it is always abnormal termination.

Q39. Can you give the most common occurred exception in your previous project.
Ans. NullPointerException, ArrayIndexOutofBoundException, StackOverFlowError, ClassCastException, NoClassDefFoundError, ExceptionInitilizerError, IllegalArgumentException, NumberFormatException, IllegalStateException, AssertionError.
Q40. Explain the cases where you used Exception Handling in your previous project?