95.7k views
3 votes
Write a Java program for user defined exception that checks the internal and external marks; if the internal marks is greater than 30 it raises the exception “Internal mark exceeded”; if the external marks is greater than 70 it raises the exception and displays the message “External mark exceeded”, Create the above exception and test the exceptions.

1 Answer

6 votes

Answer:

class MarksException extends Exception {

public MarksException(String message) {

super(message);

}

}

public class Main {

public static void main(String[] args) {

try {

checkMarks(35, 80);

} catch (MarksException e) {

System.out.println(e.getMessage());

}

}

public static void checkMarks(int internal, int external) throws MarksException {

if (internal > 30) {

throw new MarksException("Internal mark exceeded");

}

if (external > 70) {

throw new MarksException("External mark exceeded");

}

}

}

Step-by-step explanation:

User Stephen Wood
by
7.8k points