cbeust / jcommander

Command line parsing framework for Java
Apache License 2.0
1.96k stars 334 forks source link

cant catch ParameterException in top level #527

Closed dongshen closed 3 years ago

dongshen commented 3 years ago

the code like this: JCommander jcommander = new JCommander(arguments); jcommander.setProgramName(progName); try { jcommander.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); }

but we get exception but cant catch in parse(args) level. com.beust.jcommander.ParameterException: Only one main parameter allowed but found several: "parameter2" and "script.sh parameter1" at com.beust.jcommander.JCommander$MainParameter.addValue([JCommander.java:101]) at com.beust.jcommander.JCommander.parseValues([JCommander.java:782]) at com.beust.jcommander.JCommander.parse([JCommander.java:356]) at com.beust.jcommander.JCommander.parse([JCommander.java:335])

dongshen commented 3 years ago

solved, i found the same ParameterException in my local system. because the exception name is the same, so not be catch