-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical30.java
More file actions
24 lines (22 loc) · 878 Bytes
/
practical30.java
File metadata and controls
24 lines (22 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Write a program to generate customized exception named ArgumentGreaterThanOne if there is more than one argument in command line
// Custom exception class
class ArgumentGreaterThanOne extends Exception {
public ArgumentGreaterThanOne(String message) {
super(message);
}
}
public class practical30 {
public static void main(String[] args) {
try {
if (args.length > 1) {
throw new ArgumentGreaterThanOne("More than one argument is not allowed!");
} else if (args.length == 1) {
System.out.println("Successfully provided exactly 1 argument: " + args[0]);
} else {
System.out.println("No arguments were provided. (0 arguments)");
}
} catch (ArgumentGreaterThanOne e) {
System.out.println("Exception caught: " + e);
}
}
}