0% found this document useful (0 votes)
2 views2 pages

Handling DivideByZeroException in Java

The document presents a Java program that demonstrates handling a DivideByZeroException using a try-catch block. When attempting to divide by zero, an ArithmeticException is caught, and an error message is displayed. The output confirms that the program successfully handles the exception by printing 'Error: Cannot divide by zero.'

Uploaded by

Dillibabu G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Handling DivideByZeroException in Java

The document presents a Java program that demonstrates handling a DivideByZeroException using a try-catch block. When attempting to divide by zero, an ArithmeticException is caught, and an error message is displayed. The output confirms that the program successfully handles the exception by printing 'Error: Cannot divide by zero.'

Uploaded by

Dillibabu G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. WAP for handling DivideByZeroException.

public class DivideByZeroExceptionHandling {

public static void main(String[] args) {

try {

int a = 10;

int b = 0;

int result = a / b;

[Link]("Result: " + result);

} catch (ArithmeticException e) {

[Link]("Error: Cannot divide by zero.");

OUTPUT :

C:\>cd DILLIBABU

C:\DILLIBABU>javac [Link]

C:\DILLIBABU>java DivideByZeroExceptionHandling

Error: Cannot divide by zero.

C:\DILLIBABU>

You might also like