>From aec3e5e7206a076d9218e6038df6b7451ed3c5f1 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Tue, 17 Jan 2017 23:16:57 +0100
Subject: [PATCH] Cleaned up error handling in user and group CLIs.

The user and group CLIs have been modified to use Exception
instead of System.exit() such that errors can be handled
consistently.
---
 .../com/netscape/cmstools/group/GroupAddCLI.java   | 18 +++-----------
 .../com/netscape/cmstools/group/GroupFindCLI.java  | 14 ++---------
 .../netscape/cmstools/group/GroupMemberAddCLI.java | 22 ++++-------------
 .../cmstools/group/GroupMemberFindCLI.java         | 18 +++-----------
 .../cmstools/group/GroupMemberRemoveCLI.java       | 22 ++++-------------
 .../cmstools/group/GroupMemberShowCLI.java         | 22 ++++-------------
 .../netscape/cmstools/group/GroupModifyCLI.java    | 18 +++-----------
 .../netscape/cmstools/group/GroupRemoveCLI.java    | 20 ++++------------
 .../com/netscape/cmstools/group/GroupShowCLI.java  | 20 ++++------------
 .../src/com/netscape/cmstools/user/UserAddCLI.java | 18 +++-----------
 .../com/netscape/cmstools/user/UserCertAddCLI.java | 28 ++++------------------
 .../netscape/cmstools/user/UserCertFindCLI.java    | 18 +++-----------
 .../netscape/cmstools/user/UserCertRemoveCLI.java  | 18 +++-----------
 .../netscape/cmstools/user/UserCertShowCLI.java    | 18 +++-----------
 .../com/netscape/cmstools/user/UserFindCLI.java    | 14 ++---------
 .../cmstools/user/UserMembershipAddCLI.java        | 18 +++-----------
 .../cmstools/user/UserMembershipFindCLI.java       | 18 +++-----------
 .../cmstools/user/UserMembershipRemoveCLI.java     | 18 +++-----------
 .../com/netscape/cmstools/user/UserModifyCLI.java  | 18 +++-----------
 .../com/netscape/cmstools/user/UserRemoveCLI.java  | 18 +++-----------
 .../com/netscape/cmstools/user/UserShowCLI.java    | 18 +++-----------
 21 files changed, 71 insertions(+), 325 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
index 8bb529aeff4a4e7912eb0f1ee27b525f6289c87c..0ae506f3f1ee6f12e015bac58bfe871cd91e80ea 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
@@ -54,28 +54,16 @@ public class GroupAddCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Group ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Group ID specified.");
         }
 
         String groupID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupFindCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupFindCLI.java
index 3c340d8a252617e59e276f720d58370d1e05242e..dda3dacbc51fc3639eacaae3e0289a0b374a392d 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupFindCLI.java
@@ -60,21 +60,11 @@ public class GroupFindCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
index 3c953a14d6cc6939289ee748ce0ba94e19884619..cc00417733dbbdbb4330962c66c6509119182f4e 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
@@ -45,32 +45,20 @@ public class GroupMemberAddCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
-        String groupID = args[0];
-        String memberID = args[1];
+        String groupID = cmdArgs[0];
+        String memberID = cmdArgs[1];
 
         GroupMemberData groupMemberData = groupMemberCLI.groupClient.addGroupMember(groupID, memberID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
index 7a4f217f009cdb5102a00011ecb445ce2e11a352..788827abf83961b02896440070677e56f2078410 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
@@ -60,28 +60,16 @@ public class GroupMemberFindCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length < 1 || cmdArgs.length > 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         String groupID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
index 95760aa2ab87094ff0bd522a31b39cddb042aed5..89cb668559620e4abed795363005729d2301f38a 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
@@ -44,32 +44,20 @@ public class GroupMemberRemoveCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
-        String groupID = args[0];
-        String memberID = args[1];
+        String groupID = cmdArgs[0];
+        String memberID = cmdArgs[1];
 
         groupMemberCLI.groupClient.removeGroupMember(groupID, memberID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
index c04366d929482b872f7e0592acc965b9e4e814c1..a0e9f22310784c8b6be3d8ba5a36bee36764b82d 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
@@ -45,32 +45,20 @@ public class GroupMemberShowCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
-        String groupID = args[0];
-        String memberID = args[1];
+        String groupID = cmdArgs[0];
+        String memberID = cmdArgs[1];
 
         GroupMemberData groupMemberData = groupMemberCLI.groupClient.getGroupMember(groupID, memberID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupModifyCLI.java
index e26a63b7c86575b981439da0fe931a81a88d41af..f3dd2f951302d5a16a7601c311551e4d352ce794 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupModifyCLI.java
@@ -54,28 +54,16 @@ public class GroupModifyCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Group ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Group ID specified.");
         }
 
         String groupID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveCLI.java
index 0fd7d2fd0199897d43235a2a94ddb67bbd759b74..68a17483e87217b70d4d152f0f027fb7d9263af3 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveCLI.java
@@ -45,31 +45,19 @@ public class GroupRemoveCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Group ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Group ID specified.");
         }
 
-        String groupID = args[0];
+        String groupID = cmdArgs[0];
 
         groupCLI.groupClient.removeGroup(groupID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupShowCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupShowCLI.java
index 0030c083adb9b36c1963fcc0bedc83ce77a79a76..39cc66b03b1d7ac2816893fb8d94ee268034982b 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupShowCLI.java
@@ -45,31 +45,19 @@ public class GroupShowCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Group ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Group ID specified.");
         }
 
-        String groupID = args[0];
+        String groupID = cmdArgs[0];
 
         GroupData groupData = groupCLI.groupClient.getGroup(groupID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java
index 281d2ab36e784dcf8b3f61977b2f6df855e375c5..4cccd7adf9aa679a8022c9312e65da928cb2644e 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java
@@ -75,28 +75,16 @@ public class UserAddCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
index 3e96c1deea3b51c941a277efcca153303030751d..3b233cdb25df5499af96e63ec6d8b291bf574536 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
@@ -64,28 +64,16 @@ public class UserCertAddCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userID = cmdArgs[0];
@@ -95,10 +83,7 @@ public class UserCertAddCLI extends CLI {
         String encoded;
 
         if (inputFile != null && serialNumber != null) {
-            System.err.println("Error: Conflicting options: --input and --serial.");
-            printHelp();
-            System.exit(-1);
-            return;
+            throw new Exception("Conflicting options: --input and --serial.");
 
         } else if (inputFile != null) {
             if (verbose) {
@@ -122,10 +107,7 @@ public class UserCertAddCLI extends CLI {
             encoded = certData.getEncoded();
 
         } else {
-            System.err.println("Error: Missing input file or serial number.");
-            printHelp();
-            System.exit(-1);
-            return;
+            throw new Exception("Missing input file or serial number.");
         }
 
         UserCertData userCertData = new UserCertData();
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
index 9f70e20541aa576e66d00c3e24d01fa7a1eb859b..4f6980fd83a19b3b9b05e13b7f498dab074c30cc 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
@@ -60,28 +60,16 @@ public class UserCertFindCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
index 445dbb1f8a5dba95638b531a3962965836884b21..e1f15cac525be03e14c92c2446fb4c365c02439e 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
@@ -46,28 +46,16 @@ public class UserCertRemoveCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         String userID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
index 59e7b016fbab9307f540bcead3674706a49b63f4..1267dbc80ebfc84d7d5d56a2b50f5bc477c56b72 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
@@ -60,28 +60,16 @@ public class UserCertShowCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         boolean showPrettyPrint = cmd.hasOption("pretty");
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java
index 64653105fd0774f42ceb534f876af5915a4fa089..8f9b8ba7f96e540453754271cb2c9dd510e25fa6 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java
@@ -60,21 +60,11 @@ public class UserFindCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
index 8fb7adb6691f6671517d3c5824cbe0cd44e98f36..966e8ed405d58068b61054f2e244060b85b2fe91 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
@@ -45,28 +45,16 @@ public class UserMembershipAddCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         String userID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
index 037e45e1cddb243fa64618503da2f97c434ee1ee..f51fc49b50528619469e5ddbd3c8f2ffc1435a38 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
@@ -60,28 +60,16 @@ public class UserMembershipFindCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length < 1 || cmdArgs.length > 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         String userID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
index 99418c7f0a39528f5a20e8e015542dfe3f381f05..1573cc8abe4ac7931cf8decf9f22b56ec908c57a 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
@@ -44,28 +44,16 @@ public class UserMembershipRemoveCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 2) {
-            System.err.println("Error: Incorrect number of arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Incorrect number of arguments specified.");
         }
 
         String userID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java
index b0e2e8ecb0b8212171c2c2c51b157f7fe19d07a8..e632672d79ed1ba5deb7d22fd9fc5bf8345ae7f9 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java
@@ -75,28 +75,16 @@ public class UserModifyCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userId = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java
index 83db50faf6be59f43ebb5e0fac8f55762827a6fa..4ad8bf1b3ddf99955cc803b877e7d3f92cd2ead0 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java
@@ -44,28 +44,16 @@ public class UserRemoveCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java
index dafebff2cae694ab643a415ade456beab1386ce8..e46013940db068c08e7683156410eba3ea091edf 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java
@@ -45,28 +45,16 @@ public class UserShowCLI extends CLI {
     public void execute(String[] args) throws Exception {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
-            // Display usage
             printHelp();
-            System.exit(0);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No User ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No User ID specified.");
         }
 
         String userId = args[0];
-- 
2.5.5

