Example usage for java.lang IllegalArgumentException getMessage

List of usage examples for java.lang IllegalArgumentException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:ArrayEnumeration.java

public static void main(String args[]) {
    Object obj = new int[] { 2, 3, 5, 8, 13, 21 };
    ArrayEnumeration e = new ArrayEnumeration(obj);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }//  www  . j av a  2  s  .co  m
    try {
        e = new ArrayEnumeration(ArrayEnumeration.class);
    } catch (IllegalArgumentException ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:ArrayEnumeration.java

public static void main(String args[]) {
    Object obj = new int[] { 2, 3, 5, 8, 13, 21 };
    Enumeration e = new ArrayEnumeration(obj);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }// w  ww.  j a  v  a 2 s.com
    try {
        e = new ArrayEnumeration("Not an Array");
    } catch (IllegalArgumentException ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:ArrayEnumerationFactory.java

public static void main(String args[]) {
    Enumeration e = makeEnumeration(args);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }//from w w  w .ja  v a  2s .  c o m
    e = makeEnumeration(new int[] { 1, 3, 4, 5 });
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
    try {
        e = makeEnumeration(new Double(Math.PI));
    } catch (IllegalArgumentException ex) {
        System.err.println("Can't enumerate that: " + ex.getMessage());
    }
}

From source file:Delete.java

/**
 * This is the main() method of the standalone program. After checking it
 * arguments, it invokes the Delete.delete() method to do the deletion
 *//*from  ww w .  j a  v a  2 s.  c  om*/
public static void main(String[] args) {
    if (args.length != 1) { // Check command-line arguments
        System.err.println("Usage: java Delete <file or directory>");
        System.exit(0);
    }
    // Call delete() and display any error messages it throws.
    try {
        delete(args[0]);
    } catch (IllegalArgumentException e) {
        System.err.println(e.getMessage());
    }
}

From source file:Easter.java

/** Main program, when used as a standalone application */
public static void main(String[] argv) {

    if (argv.length == 0) {
        int thisYear = new GregorianCalendar().get(Calendar.YEAR);
        Calendar c = Easter.findHolyDay(thisYear);
        System.out.println(c.getTime());
    } else/* w ww  . j  a  va 2 s.co  m*/
        for (int i = 0; i < argv.length; i++) {
            int year = 0;
            try {
                year = Integer.parseInt(argv[i]);
                System.out.println(Easter.findHolyDay(year).getTime());
            } catch (IllegalArgumentException e) {
                System.err.println("Year " + argv[i] + " invalid (" + e.getMessage() + ").");
            }
        }
}

From source file:com.comcast.tvx.haproxy.MappingsLoaderMain.java

/**
 * @param args//from  w  w w. j a va  2 s . co  m
 */
public static void main(String[] args) {

    try {
        Args.parse(MappingsLoaderMain.class, args);
    } catch (IllegalArgumentException e) {

        System.out.println(e.getMessage());
        Args.usage(MappingsLoaderMain.class);
        System.exit(1);
    }

    final CuratorFramework curatorFramework = CuratorClient.getCuratorFramework(zooKeeperConnectionString);
    try {
        loadMappings(curatorFramework);
    } catch (Exception e) {
        curatorFramework.close();
        e.printStackTrace();
        System.exit(1);
    }
    curatorFramework.close();
    System.exit(0);

}

From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalWriter.java

public static void main(String[] args) throws SOMToolboxException, IOException {
    // register and parse all options
    JSAPResult config = OptionFactory.parseResults(args, OPTIONS);
    File inputVectorFile = config.getFile("inputVectorFile");
    String outputDirStr = AbstractOptionFactory.getFilePath(config, "outputDirectory");
    File outputDirBase = new File(outputDirStr);
    outputDirBase.mkdirs();//from  w  ww  .ja v  a  2 s .  c  o m
    String metricName = config.getString("metric");
    DistanceMetric metric = AbstractMetric.instantiateNice(metricName);

    int neighbours = config.getInt("numberNeighbours");
    int startIndex = config.getInt("startIndex");
    int numberItems = config.getInt("numberItems", -1);

    try {
        SOMLibSparseInputData data = new SOMLibSparseInputData(inputVectorFile.getAbsolutePath());
        int endIndex = data.numVectors();
        if (numberItems != -1) {
            if (startIndex + numberItems > endIndex) {
                System.out.println("Specified number of items (" + numberItems + ") exceeds maximum ("
                        + data.numVectors() + "), limiting to " + (endIndex - startIndex) + ".");
            } else {
                endIndex = startIndex + numberItems;
            }
        }
        StdErrProgressWriter progress = new StdErrProgressWriter(endIndex - startIndex, "processing vector ");
        // SortedSet<InputDistance> distances;
        for (int inputDatumIndex = startIndex; inputDatumIndex < endIndex; inputDatumIndex++) {

            InputDatum inputDatum = data.getInputDatum(inputDatumIndex);
            String inputLabel = inputDatum.getLabel();
            if (inputDatumIndex == -1) {
                throw new IllegalArgumentException(
                        "Input with label '" + inputLabel + "' not found in vector file '" + inputVectorFile
                                + "'; possible labels are: " + StringUtils.toString(data.getLabels(), 15));
            }

            File outputDir = new File(outputDirBase,
                    inputLabel.charAt(2) + "/" + inputLabel.charAt(3) + "/" + inputLabel.charAt(4));
            outputDir.mkdirs();
            File outputFile = new File(outputDir, inputLabel + ".txt");

            boolean fileExistsAndValid = false;
            if (outputFile.exists()) {
                // check if it the valid data
                String linesInvalid = "";
                int validLineCount = 0;
                ArrayList<String> lines = FileUtils.readLinesAsList(outputFile.getAbsolutePath());
                for (String string : lines) {
                    if (string.trim().length() == 0) {
                        continue;
                    }
                    String[] parts = string.split("\t");
                    if (parts.length != 2) {
                        linesInvalid += "Line '" + string + "' invalid - contains " + parts.length
                                + " elements.\n";
                    } else if (!NumberUtils.isNumber(parts[1])) {
                        linesInvalid = "Line '" + string + "' invalid - 2nd part is not a number.\n";
                    } else {
                        validLineCount++;
                    }
                }
                if (validLineCount != neighbours) {
                    linesInvalid = "Not enough valid lines; expected " + neighbours + ", found "
                            + validLineCount + ".\n";
                }
                fileExistsAndValid = true;
                if (org.apache.commons.lang.StringUtils.isNotBlank(linesInvalid)) {
                    System.out.println("File " + outputFile.getAbsolutePath() + " exists, but is not valid:\n"
                            + linesInvalid);
                }
            }

            if (fileExistsAndValid) {
                Logger.getLogger("at.tuwien.ifs.feature.evaluation").finer(
                        "File " + outputFile.getAbsolutePath() + " exists and is valid; not recomputing");
            } else {
                PrintWriter p = new PrintWriter(outputFile);
                SmallestElementSet<InputDistance> distances = data.getNearestDistances(inputDatumIndex,
                        neighbours, metric);
                for (InputDistance inputDistance : distances) {
                    p.println(inputDistance.getInput().getLabel() + "\t" + inputDistance.getDistance());
                }
                p.close();
            }
            progress.progress();
        }

    } catch (IllegalArgumentException e) {
        System.out.println(e.getMessage() + ". Aborting.");
        System.exit(-1);
    }
}

From source file:net.jradius.server.Main.java

public static void main(String[] args) {
    if (args.length != 1) {
        showUsage();/*from w ww  .  ja v  a 2 s  .  c o m*/
        System.exit(1);
    }

    /**
     * CADBiS daemon run
     * --->
     */
    if (JRadiusConfigurator.getInstance().getProperty("cadbis_daemon").equals("enabled"))
        CADBiS.getInstance().start();
    /**
     * <--- eof CADBiS
     */

    String configFilePath = args[0];

    try {
        File file = new File(configFilePath);
        Configuration.initialize(file);
        JRadiusServer server = new JRadiusServer();
        server.start();
    } catch (FileNotFoundException e) {
        System.err.println("Error: The configuration file '" + configFilePath + "' does not exist.");
    } catch (ConfigurationException e1) {
        System.err.println("Error: The configuration file could not be read,"
                + " because the file contains an error: " + e1.getMessage());
        showStackTrace(e1);
    } catch (SecurityException e2) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a security error occurred: " + e2.getMessage());
        showStackTrace(e2);
    } catch (IllegalArgumentException e3) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an illegal argument error occurred: " + e3.getMessage());
        showStackTrace(e3);
    } catch (ClassNotFoundException e4) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a class specified in the configuration file could not be found: "
                + e4.getMessage());
        showStackTrace(e4);
    } catch (NoSuchMethodException e5) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a method does not exist in a class specified in the configuration file: "
                + e5.getMessage());
        showStackTrace(e5);
    } catch (InstantiationException e6) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an object specified in the configuration file could not be instantiated: "
                + e6.getMessage());
        showStackTrace(e6);
    } catch (IllegalAccessException e7) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an illegal access error occurred: " + e7.getMessage());
        showStackTrace(e7);
    } catch (InvocationTargetException e8) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an invocation target exception was thrown: " + e8.getMessage());
        showStackTrace(e8);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return;
}

From source file:de.tudarmstadt.ukp.csniper.resbuild.EvaluationItemFixer.java

public static void main(String[] args) {
    connect(HOST, DATABASE, USER, PASSWORD);

    Map<Integer, String> items = new HashMap<Integer, String>();
    Map<Integer, String> failed = new HashMap<Integer, String>();

    // fetch coveredTexts of dubious items and clean it
    PreparedStatement select = null;
    try {/*  w  w w  .ja v  a 2s .  c  om*/
        StringBuilder selectQuery = new StringBuilder();
        selectQuery.append("SELECT * FROM EvaluationItem ");
        selectQuery.append("WHERE LOCATE(coveredText, '  ') > 0 ");
        selectQuery.append("OR LOCATE('" + LRB + "', coveredText) > 0 ");
        selectQuery.append("OR LOCATE('" + RRB + "', coveredText) > 0 ");
        selectQuery.append("OR LEFT(coveredText, 1) = ' ' ");
        selectQuery.append("OR RIGHT(coveredText, 1) = ' ' ");

        select = connection.prepareStatement(selectQuery.toString());
        log.info("Running query [" + selectQuery.toString() + "].");
        ResultSet rs = select.executeQuery();

        while (rs.next()) {
            int id = rs.getInt("id");
            String coveredText = rs.getString("coveredText");

            try {
                // special handling of double whitespace: in this case, re-fetch the text
                if (coveredText.contains("  ")) {
                    coveredText = retrieveCoveredText(rs.getString("collectionId"), rs.getString("documentId"),
                            rs.getInt("beginOffset"), rs.getInt("endOffset"));
                }

                // replace bracket placeholders and trim the text
                coveredText = StringUtils.replace(coveredText, LRB, "(");
                coveredText = StringUtils.replace(coveredText, RRB, ")");
                coveredText = coveredText.trim();

                items.put(id, coveredText);
            } catch (IllegalArgumentException e) {
                failed.put(id, e.getMessage());
            }
        }
    } catch (SQLException e) {
        log.error("Exception while selecting: " + e.getMessage());
    } finally {
        closeQuietly(select);
    }

    // write logs
    BufferedWriter bwf = null;
    BufferedWriter bws = null;
    try {
        bwf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(LOG_FAILED)), "UTF-8"));
        for (Entry<Integer, String> e : failed.entrySet()) {
            bwf.write(e.getKey() + " - " + e.getValue() + "\n");
        }

        bws = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(new File(LOG_SUCCESSFUL)), "UTF-8"));
        for (Entry<Integer, String> e : items.entrySet()) {
            bws.write(e.getKey() + " - " + e.getValue() + "\n");
        }
    } catch (IOException e) {
        log.error("Got an IOException while writing the log files.");
    } finally {
        IOUtils.closeQuietly(bwf);
        IOUtils.closeQuietly(bws);
    }

    log.info("Texts for [" + items.size() + "] items need to be cleaned up.");

    // update the dubious items with the cleaned coveredText
    PreparedStatement update = null;
    try {
        String updateQuery = "UPDATE EvaluationItem SET coveredText = ? WHERE id = ?";

        update = connection.prepareStatement(updateQuery);
        int i = 0;
        for (Entry<Integer, String> e : items.entrySet()) {
            int id = e.getKey();
            String coveredText = e.getValue();

            // update item in database
            update.setString(1, coveredText);
            update.setInt(2, id);
            update.executeUpdate();
            log.debug("Updating " + id + " with [" + coveredText + "]");

            // show percentage of updated items
            i++;
            int part = (int) Math.ceil((double) items.size() / 100);
            if (i % part == 0) {
                log.info(i / part + "% finished (" + i + "/" + items.size() + ").");
            }
        }
    } catch (SQLException e) {
        log.error("Exception while updating: " + e.getMessage());
    } finally {
        closeQuietly(update);
    }

    closeQuietly(connection);
}

From source file:com.zimbra.cs.service.util.ItemDataFile.java

public static void main(String[] args) {
    String cset = null;/*w w w.  j  a  va  2s . c o m*/
    Options opts = new Options();
    CommandLineParser parser = new GnuParser();

    opts.addOption("a", "assemble", false, "assemble backup");
    opts.addOption("c", "charset", true, "path charset");
    opts.addOption("e", "extract", false, "extract backup");
    opts.addOption("h", "help", false, "help");
    opts.addOption("l", "list", false, "list backup");
    opts.addOption("n", "nometa", false, "ignore metadata");
    opts.addOption("p", "path", true, "extracted backup path");
    opts.addOption("t", "types", true, "item types");
    ZimbraLog.toolSetupLog4j("ERROR", null);
    try {
        CommandLine cl = parser.parse(opts, args);
        String path = ".";
        String file = null;
        boolean meta = true;
        Set<MailItem.Type> types = null;

        if (cl.hasOption('c')) {
            cset = cl.getOptionValue('c');
        }
        if (cl.hasOption('n')) {
            meta = false;
        }
        if (cl.hasOption('p')) {
            path = cl.getOptionValue('p');
        }
        if (cl.hasOption('t')) {
            try {
                types = MailItem.Type.setOf(cl.getOptionValue('t'));
            } catch (IllegalArgumentException e) {
                throw MailServiceException.INVALID_TYPE(e.getMessage());
            }
        }
        if (cl.hasOption('h') || cl.getArgs().length != 1) {
            usage(opts);
        }
        file = cl.getArgs()[0];
        if (cl.hasOption('a')) {
            create(path, types, cset, new FileOutputStream(file));
        } else if (cl.hasOption('e')) {
            extract(new FileInputStream(file), meta, types, cset, path);
        } else if (cl.hasOption('l')) {
            list(file.equals("-") ? System.in : new FileInputStream(file), types, cset, System.out);
        } else {
            usage(opts);
        }
    } catch (Exception e) {
        if (e instanceof UnrecognizedOptionException)
            usage(opts);
        else
            e.printStackTrace(System.out);
        System.exit(1);
    }
}