Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

ArithmeticException Program

package day3_4;

/**

* Generate ArithmeticException

*

* @author Ritesh

*

*/

public class Arithmetic {

/**

* In try block it generates arithmetic exception that would be handled by

* catch block.

*/

public static void generateArithmeticException() {

try {

// divide by zero exception will be generated here

int intNo = 1 / 0;

} catch (ArithmeticException e) {

System.out.println("Error : Arithmetic Exception Genereated!!");

e.printStackTrace();

}

}

/**

* excution begin from here

*

* @param args

* commandline arguments

*/

public static void main(String[] args) {

generateArithmeticException();

}

}

No comments:

Post a Comment

Followers