Java ExceptionHandling

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Exception Handling

Q1. Write a java program, which read two numbers a and b and compute a/(a-b). The program
should check the value of (a-b) before dividing with a, it should throw an exception if (a-b) is
zero. In the exception handler the program should display appropriate message to the user.
Q2. Write a java program which handle multiple number of exception.
Q3. Write a java program , where the exception throws from a function and handle by the
called function. Placed the finally block in both the function.
Q4. Define a class called BankAccount with the following properties and methods:
Properties: String accName, int accNum, double accBalance
Methods:
void deposit(int amt)
void withdraw(int amt),
void transfer (BankAccount acc1, BankAccount acc2, int amt)
Assume that an account needs to have a minimum balance of 500. If an attempt is made to
withdraw or transfer, which results in balance going below 500, throw a user defined exception
called MinimumBalanceException. Use throw and throws wherever necessary.
Note: Your code must have user defined exception.
Q5. Write a java program that take command line arguments as user name and password. The
program throw exception as follows.
i. ArithmeticException if user passed no command line arguments
ii. ArrayIndexOutOfBounds , if user passed one command line arguments.
iii. WrongCredential ( Note: User defined Exception ), if mismatch of user name and
password.

Pradipta Kumar Pattanayak


Department of Computer Science.
Silicon Institute of Technology

You might also like