Java program to check marks out of Bound exception.
import java.util.Scanner;
public class MarksProcessor {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the marks: ");
int marks = scanner.nextInt();
try {
validateMarks(marks);
System.out.println("Marks are within the valid range.");
} catch (MarksOutOfBoundsException e) {
System.out.println("Exception: " + e.getMessage());
}
}
private static void validateMarks(int marks) throws MarksOutOfBoundsException {
if (marks > 100) {
throw new MarksOutOfBoundsException("Marks out of Bound: Marks cannot be greater than 100.");
}
}
}
Comments
Post a Comment