/WT-LAB-10

Programs on Java Exception Handling

Primary LanguageJava

WT-LAB-10

Programs on Java Exception Handling

Questions:-

Q1. Write a Java program to generate an ArrayIndexOutofBoundsException and handle it using catch statement.

Q2. A subclass exception must appear before super-class exception. Justify this with suitable Java programs.

Q3. Write a Java program to illustrate try..catch..finally block.

Q4. Write a Java class which has a method called ProcessInput(). This method checks the number entered by the user. If the entered number is negative then throw an user defined exception called NegativeNumberException, otherwise it displays the double value of the entered number.

Q5. Write a program to create user defined exceptions called HrsException, MinException and SecException. Create a class Time which contains data members hours, minutes, seconds and throw the user defined exceptions if hours (>24 & <0),minutes(>60 & <0),seconds(>60 & <0).

Q6. Create an user defined exception named Check Argument to check the number of arguments passed through command line. If the number of arguments is less than four, throw the Check Argument exception, else print the addition of squares of all the four elements.

Q7. Write a java program to create Account with 500 rupee minimum balance, deposit amount, withdraw amount and also throws LessBalanceException which returns the statement that says withdraw amount is not valid.

Q8. Write a java program to implement a stack class having methods push () and pop(). These methods must be designed to throw user defined exception when the stack is empty or full.