What is an
Exception Handling?
Exception Handling What is an Exception ? Let us see what happens when an exception occurs and is not handled properly When you compile and run the following program public class Test{
the execution of the Test stops and this is caused by the division by zero at - x/y - an exception has been thrown but has not been handled properly. How to handle an Exception ? To handle an Exception, enclose the code that is likely to throw an exception in a try block and follow it immediately by a catch clause as follows public class Test{
The output of the above program is as follows attempt to divide by 0
the statement - System.out.println("after didvision") - is NOT executed, once an exception is thrown, the program control moves out of the try block into the catch block.
More Java Questions Java BooksJava 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.
|