The Purpose of Try

What is the purpose of try?

We should maintain all risky code inside the try block.
 

What is the purpose of catch block?

We have to maintain all Exception Handling code inside the catch block.
 

Is try with multiple catch block is possible?

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
                }
 

If try with multiple catch block present is order of catch blocks important in which order we have to take?

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.

Java Tips

See also
Java Multi Threading

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.