Fix program crash when try to show command helper info (#24809)
diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.java b/examples/java-matter-controller/java/src/com/matter/controller/Main.java
index ffeefb4..0e24c6d 100644
--- a/examples/java-matter-controller/java/src/com/matter/controller/Main.java
+++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.java
@@ -112,9 +112,6 @@
try {
commandManager.run(args);
- } catch (IllegalArgumentException e) {
- logger.log(Level.INFO, "Arguments init failed with exception: " + e.getMessage());
- System.exit(1);
} catch (Exception e) {
logger.log(Level.INFO, "Run command failed with exception: " + e.getMessage());
System.exit(1);
diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java
index 2e1b373..47e184e 100644
--- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java
+++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java
@@ -96,8 +96,14 @@
// need skip over binary and command name and only get arguments
String[] temp = Arrays.copyOfRange(args, 2, args.length);
- command.initArguments(temp.length, temp);
- showCommand(args[0], command);
+ try {
+ command.initArguments(temp.length, temp);
+ } catch (IllegalArgumentException e) {
+ logger.log(Level.INFO, "Arguments init failed with exception: " + e.getMessage());
+ showCommand(args[0], command);
+ System.exit(1);
+ }
+
command.run();
}