How To Implement Exception In Java

Rate this article
0 out of 5
In this tutorial we will show you how to implement exception in java. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.

 
Source Code
exception1.java

//This program is to impliment exception handling
import java.io.*;
class exception1
{
public static void main(String args[])
{
int x,y,a=5,b=5,c=5;
//try block starts
try
{
x=a/(b-c);
System.out.println("No exception");
}
//catch block starts
catch(ArithmeticException e)
{
System.out.println("Division by zero"+e);
}
//second catch block
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index out of bound"+e);
}
//The finally block
finally
{
System.out.println("The codes after catch block");
}
}
}



Source Code

Joined Date :04-Feb-2013
Articles
Posted
27
Messages
Posted
0


   
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud