M
mark jason
hi,
I have an application that expects a certain number of command line
arguments.I need to check the number of command line args and if
sufficient number of arguments are not provided ,would like to print
the error message and exit.I have heard that using
System.exit(somenumber) is frowned upon.Which is the best practice?
regards
mark.
class MyApp{
....
public static void main(String[] args){
if (args.length< 4){
System.out.println("Usage: java MyApp fname sname
citycode statecode");
System.exit(1);
}
String firstname = args[0];
String surname = args[1];
String cityCode = args[2];
String stateCode = args[3];
new MyApp().process(firstname, surname, cityCode, stateCode);
...
}
}
I have an application that expects a certain number of command line
arguments.I need to check the number of command line args and if
sufficient number of arguments are not provided ,would like to print
the error message and exit.I have heard that using
System.exit(somenumber) is frowned upon.Which is the best practice?
regards
mark.
class MyApp{
....
public static void main(String[] args){
if (args.length< 4){
System.out.println("Usage: java MyApp fname sname
citycode statecode");
System.exit(1);
}
String firstname = args[0];
String surname = args[1];
String cityCode = args[2];
String stateCode = args[3];
new MyApp().process(firstname, surname, cityCode, stateCode);
...
}
}