Lab Manual - Lab 13-Exception Handling
Lab Manual - Lab 13-Exception Handling
Objective:
● To understand exception handling and its implementation
Task:
1. Write a program that takes 10 positive integers from user and prints the sum. If any negative
value is entered, the program should catch it as an exception and display “Input positive integer
only”. The program must continue taking input until it gets 10 positive integers.
2. Write a program that creates an integer array of size 100 and initialize it with random values:
int a = (int) (Math.random() * 10000);
The program then takes an integer from user, use it as an index and tries to print the
corresponding element of that array. If index is out of array size, the program should catch it
and display appropriate message.
3. Create a Triangle class. Now create IllegalTriangleException class that extends Exception. If
the sum of any two sides is not greater than the third side, the Triangle class should throw
IllegalTriangleException.