Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Exception Handling FAQs


Untitled Document

Q5.What is the purpose of try?
Ans We should maintain all risky code inside the try block.
Q6. What is the purpose of catch block?
Ans.We have to maintain all Exception Handling code inside the catch block.
Q7.  Is try with multiple catch block is possible?
Ans. The way of handling an exception is varied from exception to exception compulsory we have to write a separate catch block for every exception. Hence try will multiple catch block is possible and it is recommended to use.
                Example:
                try{
                                //Risky code
                }
                catch(IOException e)
                {
                                //Hndling code for IOException
                }
                catch(ArithmeticException e)
                {
                                //handling code for AE
                }
                catch(NullPointerExcetpion e)
                {
                                // handling code for NPE
                }
                catch(Exception e)
                {
                                //default exception handling code
                }

Q8. If try with multiple catch block present is order of catch blocks important in which order we have to take?
Ans. If try with multiple catch block present then the order of catch block is very important it should be from child to parent but not from parent to child.