0% found this document useful (0 votes)
8 views2 pages

Custom Exception Code

The document contains Java code for a banking application with a class 'BankMain' that allows deposits only above 999, throwing an 'IllegalDepositException' for lower amounts. The 'IllegalDepositException' class extends the Exception class to handle specific deposit errors. The 'Testmain' class demonstrates the functionality by attempting to deposit an invalid amount and catching the exception to print the error message.

Uploaded by

yashraj25254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Custom Exception Code

The document contains Java code for a banking application with a class 'BankMain' that allows deposits only above 999, throwing an 'IllegalDepositException' for lower amounts. The 'IllegalDepositException' class extends the Exception class to handle specific deposit errors. The 'Testmain' class demonstrates the functionality by attempting to deposit an invalid amount and catching the exception to print the error message.

Uploaded by

yashraj25254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

buisness classs

package madamjipractice;

public class BankMain {

String name;
double balance;

public BankMain(String name, double balance) {


super();
[Link] = name;
[Link] = balance;
}

public void deposit(double amount)throws IllegalDepositException {

if(amount>=1000) {
balance+=amount;
}
else {
throw new IllegalDepositException("Sorry ! you have to deposit more
than 999");
}
}
}

exception class

package madamjipractice;

public class IllegalDepositException extends Exception {

public IllegalDepositException(String message) {


super(message);
}

main class

package madamjipractice;

public class Testmain {

public static void main(String[] args) {

BankMain b1 = new BankMain("Shivay" , 1000);

try{
[Link](000);

}
catch(IllegalDepositException e) {
[Link]([Link]());
}

}
}

You might also like