/**
 * Copyright (c) 2013, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for
 * the specific language governing permissions and limitations under the
 * License.
 */
package com.cloudera.science.ml.client;

import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.cloudera.science.ml.client.cmd.Command;
import com.cloudera.science.ml.client.cmd.CommandException;
import com.cloudera.science.ml.client.cmd.KMeansAssignmentCommand;
import com.cloudera.science.ml.client.cmd.KMeansCommand;
import com.cloudera.science.ml.client.cmd.KMeansSketchCommand;
import com.cloudera.science.ml.client.cmd.NormalizeCommand;
import com.cloudera.science.ml.client.cmd.SampleCommand;
import com.cloudera.science.ml.client.cmd.SummaryCommand;
import com.google.common.collect.ImmutableSortedMap;

public class Main extends Configured implements Tool {
  
  private JCommander jc;
  private Help help = new Help();
  
  private static final Map<String, Command> COMMANDS = ImmutableSortedMap.<String, Command>naturalOrder()
      .put("sample", new SampleCommand())
      .put("summary", new SummaryCommand())
      .put("normalize", new NormalizeCommand())
      .put("kassign", new KMeansAssignmentCommand())
      .put("ksketch", new KMeansSketchCommand())
      .put("kmeans", new KMeansCommand())
      .build();
  
  public Main() {
    jc = new JCommander(this);
    jc.addCommand("help", help, "-help", "--help");
    for (Map.Entry<String, Command> e : COMMANDS.entrySet()) {
      jc.addCommand(e.getKey(), e.getValue());
    }
  }
  
  @Override
  public int run(String[] args) throws Exception {
    try {
      jc.parse(args);
    } catch (ParameterException pe) {
      System.err.println(pe.getMessage());
      return 1;
    }
    
    if ("help".equals(jc.getParsedCommand())) {
      return help.usage(jc, COMMANDS);
    }
    
    Command cmd = COMMANDS.get(jc.getParsedCommand());
    if (cmd == null) {
      return help.usage(jc, COMMANDS);
    }
    try {
      return cmd.execute(getConf());
    } catch (CommandException ce) {
      System.err.println("Error: " + ce.getMessage());
      return 1;      
    } catch (IllegalArgumentException e) {
      System.err.println("Argument Error: " + e.getMessage());
      return 1;
    }
  }
  
  public static void main(String[] args) throws Exception {
    int rc = ToolRunner.run(new Configuration(), new Main(), args);
    System.exit(rc);
  }
}

@@ -2688,16 +2688,24 @@
 rintln(%22
+Command 
 Error: %22
@@ -2861,32 +2861,148 @@
       return 1;%0A
+    %7D catch (IllegalStateException e) %7B%0A      System.err.println(%22State Error: %22 + e.getMessage());%0A      return 1;%0A
     %7D%0A  %7D%0A  %0A  p

Add handler for ISEs to the Main.java class