0% found this document useful (0 votes)
4 views4 pages

Java Exception Handling Examples

The document outlines four programming problems related to exception handling in Java. Problem 7.1 involves creating an array and handling ArrayIndexOutOfBoundsException, while Problem 7.2 focuses on arithmetic operations with a retry option for ArithmeticException. Problems 7.3 and 7.4 demonstrate the use of throw and throws, and creating a banking system with a custom InsufficientFundsException, respectively.

Uploaded by

nikhil.cse9
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)
4 views4 pages

Java Exception Handling Examples

The document outlines four programming problems related to exception handling in Java. Problem 7.1 involves creating an array and handling ArrayIndexOutOfBoundsException, while Problem 7.2 focuses on arithmetic operations with a retry option for ArithmeticException. Problems 7.3 and 7.4 demonstrate the use of throw and throws, and creating a banking system with a custom InsufficientFundsException, respectively.

Uploaded by

nikhil.cse9
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

EXPERIMENT-7

PROBLEM7.1:-
Create an array with ve elements. Write a program that prompts the user to
enter an index and then prints the corresponding array element. Handle the
ArrayIndexOutOfBoundsExcep on" if the entered index is invalid.

SOLUTION:-

OUTPUT:-
fi
ti
PROBLEM7.2:-
Write a program that performs arithme c opera ons. If an
"Arithme cExcep on" occurs (e.g., division by zero), provide an op on to
retry the opera on.

SOLUTION:-

OUTPUT:-
ti
ti
ti
ti
ti
ti
PROBLEM7.3:-
Demonstrate the use of throw and throws using an example

SOLUTION:-

OUTPUT:-
PROBLEM7.4:-
Create a program represen ng a simple banking system. De ne a custom
excep on "Insu cientFundsExcep on" and throw it if a user a empts to
withdraw more money than their account balance.

SOLUTION:-

OUTPUT:-
ti
ffi
ti
ti
fi
tt

You might also like