0% found this document useful (0 votes)
15 views1 page

Experiment No - 6

Uploaded by

kajal visrani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Experiment No - 6

Uploaded by

kajal visrani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Experiment No: 6

//Title:-Program on Exception Handling

Source Code:-
public class ExceptionHandlingExample6
{
public static void main(String[] args)
{
try
{
int result = divide(10, 0);
System.out.println("Result: " + result);
}
catch (ArithmeticException e)
{
System.err.println("Error: Cannot divide by zero.");
}
catch (Exception e)
{
System.err.println("Error: An unexpected error occurred: " + e.getMessage());
}
finally
{
System.out.println("Division attempt completed.");
}
}

public static int divide(int numerator, int denominator)


{
return numerator / denominator;
}
}

Output:-
D:\>javac ExceptionHandlingExample6.java

D:\>java ExceptionHandlingExample6
Error: Cannot divide by zero.
Division attempt completed.

You might also like