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