Search This Blog

27 June, 2011

Exception handling: Java specific part-2


Part - 2




Exceptions: try, throw, catch sequence


• The following code is an example of a basic
try-throw-catch sequence.


public class CatchException
{
public static void main(String args[])
{
int a = 1;
int b = 0;
try //start try block
{
System.out.println (“Trying...”);
int c = a/b; //exception is thrown
}
catch (ArithmeticException e)//and caught
{
System.out.println (“Well caught”);
}
System.out.println (“Normal program exit”);
}
}


• Output: Trying...
Well caught
Normal program exit.


<<<-Part - 1      ------------------------   Part - 3 >>>                                                        

No comments:

Post a Comment

Meetme@