Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Exception getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:at.riemers.velocity2js.velocity.Velocity2Js.java

/**
 * @param args the command line arguments
 *///from  w  w  w .  ja  va2 s  .c  o  m
public static void main(String[] args) {
    try {
        if (args.length == 0) {
            printUsage();
            return;
        }

        if (args[0].equals("-d") && args.length >= 3) {
            String resource = null;
            if (args.length >= 4) {
                resource = args[3];
            }
            List<I18NBundle> bundles = getBundles(resource);

            Velocity2Js.generateDir(args[1], args[2], bundles);
            return;
        }

        if (args[0].equals("-f") && args.length >= 4) {

            Properties p = new Properties();
            p.setProperty("resource.loader", "file");

            p.setProperty("file.resource.loader.description", "Velocity File Resource Loader");
            p.setProperty("file.resource.loader.class",
                    "org.apache.velocity.runtime.resource.loader.FileResourceLoader");

            p.setProperty("file.resource.loader.path", args[1]);

            Velocity2Js.init(p);

            String function = createFunctionName(args[2]);
            String resource = null;
            if (args.length >= 5) {
                resource = args[4];
            }
            List<I18NBundle> bundles = getBundles(resource);

            for (I18NBundle bundle : bundles) {
                String fname = args[3];
                int e = args[3].lastIndexOf('.');
                if (e <= 0 || e > args[3].length())
                    e = args[3].length();
                fname = args[3].substring(0, e) + bundle.getLocale() + args[3].substring(e);

                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(fname), "UTF8"));
                Velocity2Js.generate(args[2], function, writer, bundle.getBundle());
                writer.flush();
                writer.close();
            }

            return;
        }

        printUsage();
        return;

    } catch (ResourceNotFoundException rnfe) {
        log.error("[velocity2js] : cannot find template : " + rnfe.getMessage());
    } catch (ParseErrorException pee) {
        log.error("[velocity2js] :  Syntax error in template :" + pee);
    } catch (Exception ex) {
        System.out.flush();
        log.error("[velocity2js] :  unknown error " + ex.getMessage());
        ex.printStackTrace(System.out);
        System.out.println(ex.getLocalizedMessage());
        System.exit(1);
    }
}

From source file:chibi.gemmaanalysis.cli.deprecated.ProbeMapperCli.java

public static void main(String[] args) {
    ProbeMapperCli p = new ProbeMapperCli();
    Exception e = p.doWork(args);
    if (e != null) {
        System.err.println(e.getLocalizedMessage());
        log.error(e, e);/* w  w  w  . j a v a 2s . c o m*/
    }
}

From source file:com.weavers.duqhan.business.impl.ProductServiceImpl.java

public static void main(String[] args) {
    int[] pageNumber = new int[499];
    Random randomObj = new Random();
    for (int i = 0; i < 498; i++) {
        pageNumber[i] = (randomObj.ints(2, 500).findFirst().getAsInt());
    }//from   ww w .  ja  v a 2  s.  co  m
    try {
        for (int i = 0; i < 498; i++) {
            System.out.println("nexturlnexturlnexturlnexturl====" + pageNumber[i]);
        }
    } catch (Exception ex) {
        System.out.println("(=============================================)DATE: " + new Date().toString()
                + ex.getLocalizedMessage());
    }
}

From source file:fr.certu.chouette.command.Command.java

/**
 * @param args/*  w  w w . j ava  2s .c om*/
 */
public static void main(String[] args) {
    // pattern partially work
    String[] context = { "classpath*:/chouetteContext.xml" };

    if (args.length >= 1) {
        if (args[0].equalsIgnoreCase("-help") || args[0].equalsIgnoreCase("-h")) {
            printHelp();
            System.exit(0);
        }

        if (args[0].equalsIgnoreCase("-noDao")) {
            List<String> newContext = new ArrayList<String>();
            PathMatchingResourcePatternResolver test = new PathMatchingResourcePatternResolver();
            try {
                Resource[] re = test.getResources("classpath*:/chouetteContext.xml");
                for (Resource resource : re) {
                    if (!resource.getURL().toString().contains("dao")) {
                        newContext.add(resource.getURL().toString());
                    }
                }
                context = newContext.toArray(new String[0]);
                dao = false;
            } catch (Exception e) {

                System.err.println("cannot remove dao : " + e.getLocalizedMessage());
            }
        }
        applicationContext = new ClassPathXmlApplicationContext(context);
        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
        Command command = (Command) factory.getBean("Command");

        initDao();

        command.execute(args);

        closeDao();

        System.runFinalization();

    } else {
        printHelp();
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java

/**
 * Launch the application.// www  .ja v  a 2s  .com
 * 
 * @param args
 */
public static void main(String[] args) {
    StartSplashWindow splashWin = null;
    Thread tr = null;
    //
    // Kommandozeilenargumente parsen
    //
    try {
        if (!parseCliOptions(args)) {
            System.err.println("Error while scanning CLI-Args....");
            System.exit(-1);
        }
    } catch (Exception ex2) {
        System.err.println("Error while scanning CLI-Args....");
        System.err.println(ex2.getLocalizedMessage());
        System.exit(-1);
    }
    //
    // So, hier knnte ich splashen, alle "gefhrlichen" Sachen sind erledigt
    //
    splashWin = new StartSplashWindow();
    tr = new Thread(splashWin);
    tr.start();
    try {
        Thread.sleep(500);
    } catch (InterruptedException ex1) {
    }
    //
    // GUI starten
    //
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getLookAndFeel());
                // Set cross-platform Java L&F (also called "Metal")
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            } catch (UnsupportedLookAndFeelException ex) {
                System.out.print("fallback to standart look an feel..");
            } catch (ClassNotFoundException ex) {
                System.out.print("fallback to standart look an feel..");
            } catch (InstantiationException ex) {
                System.out.print("fallback to standart look an feel..");
            } catch (IllegalAccessException ex) {
                System.out.print("fallback to standart look an feel..");
            }
            try {
                //
                // das Mainobjekt erzeugen
                //
                MainCommGUI window = new MainCommGUI();
                window.frmMainWindow.setVisible(true);
            } catch (Exception e) {
                System.err.println("Exception: " + e.getLocalizedMessage() + "\n");
                e.printStackTrace();
            }
        }
    });
    splashWin.terminate();
}

From source file:de.unibi.techfak.bibiserv.util.codegen.Main.java

public static void main(String[] args) {
    // check &   validate cmdline options
    OptionGroup opt_g = getCMDLineOptionsGroups();
    Options opt = getCMDLineOptions();/* w  w w  . j  a v  a  2  s  . com*/
    opt.addOptionGroup(opt_g);

    CommandLineParser cli = new DefaultParser();
    try {
        CommandLine cl = cli.parse(opt, args);

        if (cl.hasOption("v")) {
            VerboseOutputFilter.SHOW_VERBOSE = true;
        }

        switch (opt_g.getSelected()) {
        case "V":
            try {
                URL jarUrl = Main.class.getProtectionDomain().getCodeSource().getLocation();
                String jarPath = URLDecoder.decode(jarUrl.getFile(), "UTF-8");
                JarFile jarFile = new JarFile(jarPath);
                Manifest m = jarFile.getManifest();
                StringBuilder versionInfo = new StringBuilder();
                for (Object key : m.getMainAttributes().keySet()) {
                    versionInfo.append(key).append(":").append(m.getMainAttributes().getValue(key.toString()))
                            .append("\n");
                }
                System.out.println(versionInfo.toString());
            } catch (Exception e) {
                log.error("Version info could not be read.");
            }
            break;
        case "h":
            HelpFormatter help = new HelpFormatter();
            String header = ""; //TODO: missing infotext 
            StringBuilder footer = new StringBuilder("Supported configuration properties :");
            help.printHelp("CodeGen -h | -V | -g  [...]", header, opt, footer.toString());
            break;
        case "g":
            // target dir
            if (cl.hasOption("t")) {
                File target = new File(cl.getOptionValue("t"));
                if (target.isDirectory() && target.canExecute() && target.canWrite()) {
                    config.setProperty("target.dir", cl.getOptionValue("t"));
                } else {
                    log.error("Target dir '{}' is inaccessible!", cl.getOptionValue("t"));
                    break;
                }
            } else {
                config.setProperty("target.dir", System.getProperty("java.io.tmpdir"));
            }

            // project dir
            if (cl.hasOption("p")) {
                File project = new File(cl.getOptionValue("p"));
                if (!project.exists()) {
                    if (!project.mkdirs()) {
                        log.error("Project dir '{}' can't be created!", cl.getOptionValue("p"));
                        break;
                    }
                }

                if (project.isDirectory() && project.canExecute() && project.canWrite()) {
                    config.setProperty("project.dir", cl.getOptionValue("p"));
                } else {
                    log.error("Project dir '{}' is inaccessible!", cl.getOptionValue("p"));
                    break;
                }
            }

            generateAppfromXML(cl.getOptionValue("g"));
            break;
        }
    } catch (ParseException e) {
        log.error("ParseException occurred while parsing cmdline arguments!\n{}", e.getLocalizedMessage());
    }

}

From source file:Main.java

public static String getMessage(Exception e) {
    String msg = e.getLocalizedMessage();
    if (msg == null && e.getCause() != null) {
        msg = e.getCause().getMessage();
    }//from   w w w  . j  a v a 2s .com
    return msg;
}

From source file:Main.java

public static boolean writeImage(File file, Bitmap mBitmap) {
    try {/*from w  ww  .  ja v a2  s. c o  m*/
        FileOutputStream fo = new FileOutputStream(file);
        mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fo);
        fo.flush();
        fo.close();
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
        return false;
    }
    return true;
}

From source file:Main.java

private static String getExceptionDescription(Exception exception) {
    return exception != null
            ? exception.getLocalizedMessage() + "\n" + exception.getMessage() + "\ncause: "
                    + exception.getCause()
            : "No description";
}

From source file:Main.java

public static void displayErrorDialog(Activity activity, Exception e) {
    String message = e.getLocalizedMessage();
    if (message == null || message == "") {
        message = e.getClass().getName();
    } else {//w w w  .  ja v a 2 s.  c  o m
        message = e.getClass().getName() + ": " + message;
    }

    Log.e(activity.getClass().toString(), "Exception: " + message, e);

    final String title = "Error";

    displayInfoBox(activity, title, message);
}