public void testStartWithErrorArg() {
    AtomicBoolean stopCalled = new AtomicBoolean(false);
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    ServerCommandLine commandLine =
        new ServerCommandLine("test-cli", writer) {
          @Override
          protected void start() throws IoTDBException {
            throw new IoTDBException("Error", 23);
          }

          @Override
          protected void remove(Set<Integer> nodeIds) {
            stopCalled.set(true);
          }
        };
    int returnCode = commandLine.run(new String[] {"-s"});

    Assert.assertEquals(23, returnCode);
    // Nothing should have been output on the console.
    String consoleOutput = out.toString();
    Assert.assertTrue(consoleOutput.contains("An error occurred while running the command"));
    // Only the start method should have been called.
    Assert.assertFalse(stopCalled.get());
  }
In this test, the commandline is called with the start option. The start method should be
called, however there an exception is thrown, which should be caught.
iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/ServerCommandLineTest.java