1// Aim: Program to perform Exception Handling operations (ClassNotFoundException and IllegalArgumentException).
2public class ClassnotfoundexceptionAndIllegalargumentexception {
3
4 public static void main(String[] args) {
5 try {
6 loadClass("anything");
7 } catch (ClassNotFoundException e) {
8 System.out.println("Class not found: " + e.getMessage());
9 }
10
11 try {
12 checkNumber(-1);
13 } catch (IllegalArgumentException e) {
14 System.out.println("Illegal argument: " + e.getMessage());
15 }
16 }
17
18 public static void loadClass(String className) throws ClassNotFoundException {
19 Class.forName(className);
20 }
21
22 public static void checkNumber(int number) {
23 if (number < 0) {
24 throw new IllegalArgumentException("Number must be non-negative");
25 }
26 }
27}