0% found this document useful (0 votes)
6 views

Exception Handling Program

Uploaded by

suhasm11111111
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)
6 views

Exception Handling Program

Uploaded by

suhasm11111111
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

//JAVA Program to demonstrate use of throw, throws, try, catch and finally blocks:

import java.io.*;
class MinBalanceException extends Exception
{
MinBalanceException(String message)
{
super(message);
}
}
public class bank
{
public void withdraw(float w,float b) throws MinBalanceException
{
if((b-w)<1000)
{
throw new MinBalanceException("You cant withdraw this much of amount");
}
else
{
b=b-w;
System.out.println("Current balance is "+b);
}
}
public static void main(String args[])
{

bank b=new bank();


try
{
b.withdraw(500,5000); // statement generates exception so kept in try block
}
catch(MinBalanceException m)
{
System.out.println(m); // MinBalanceException type of exception is caught here
}
catch(Exception m)
{
System.out.println(m); // Super class Exception type of exception is caught here
}
Finally
{
System.out.println(“If no try and catch blocks are caught exceptions then finally will caught”);
}
}
}

You might also like