0% found this document useful (0 votes)
8 views

JPR Practical No 9

program on Exception handling in java
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)
8 views

JPR Practical No 9

program on Exception handling in java
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
You are on page 1/ 2

JAVA With OOP Name: Mukta rahegaonkar

Practical no 9

Exception Handling:

 Input:
import java.util.Scanner;
public class ExceptionHandling {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
System.out.print("Enter a number: ");
int number = scanner.nextInt();
int result = 10 / number;
System.out.println("Result: " + result);
} catch (ArithmeticException e) {
System.out.println("Error: Cannot divide by zero. Please enter a non-zero number.");
} catch (Exception e) {
System.out.println("An unexpected error occurred: " + e.getMessage());
} finally {
System.out.println("Finally block executed.");
if (scanner != null) {
scanner.close();
}
}
}
}
 Output:
JAVA With OOP Name: Mukta rahegaonkar

 Code:

import java.io.*;
class FinalException {
public static void main(String[] args)
{
try {
System.out.println("inside try block");
System.out.println(34 / 2);
}
catch (ArithmeticException e) {
System.out.println("Arithmetic Exception");
}
finally {
System.out.println( "finally : It execute always.");
}
}
}

 Output:

You might also like