Example usage for java.lang Exception printStackTrace

List of usage examples for java.lang Exception printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.konakart.ApiExample.java

/**
 * @param args/* w  ww.  java 2 s. co m*/
 */
public static void main(String[] args) {
    try {
        /*
         * Instantiate a KonaKart Engine instance
         */
        Class<?> engineClass = Class.forName(ws_engine_implementation);
        eng = (KKEngIf) engineClass.newInstance();

        /*
         * Login with default credentials
         */
        //sessionId = eng.login(DEFAULT_USERNAME, DEFAULT_PASSWORD);
        //log.info(DEFAULT_USERNAME + " logged in successfully and got session " + sessionId);

        log.info("Manufacturers:\n");
        ManufacturerIf[] manus = eng.getAllManufacturers();
        for (int m = 0; m < manus.length; m++) {
            log.info("\t" + manus[m].getName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.talent.nio.utils.NetUtils.java

/**
 * @param args//from www  .j a v a2s.c om
 */
public static void main(String[] args) {
    try {
        long start1 = System.currentTimeMillis();
        boolean isConnect = isConnectable("127.0.0.1", 9898);

        long end1 = System.currentTimeMillis();
        System.out.println(isConnect + ":" + (end1 - start1) + "");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:PooledConnectionExample.java

public static void main(String[] args) {
    Connection connection = null;
    Statement statement = null;/*  w  w  w  . j  a  v a  2 s .c  om*/
    ResultSet resultSet = null;

    try {
        connection = getConnection();
        statement = connection.createStatement();
        String selectEmployeesSQL = "SELECT * FROM employees";
        resultSet = statement.executeQuery(selectEmployeesSQL);

        while (resultSet.next()) {
            printEmployee(resultSet);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        closeAll(resultSet, statement, connection);
    }
}

From source file:RetrievingLdapName.java

public static void main(String[] args) {

    // Set up the environment for creating the initial context
    Hashtable<String, Object> env = new Hashtable<String, Object>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

    try {// w w  w.  j a v  a 2  s  . c o  m
        // Create initial context
        DirContext ctx = new InitialDirContext(env);

        NamingEnumeration answer = ctx.search("ou=People", null);

        // Print the answer
        while (answer.hasMore()) {
            SearchResult sr = (SearchResult) answer.next();
            String name = sr.getNameInNamespace();
            System.out.println(name);
            LdapName dn = new LdapName(name);

            // do something with the dn
        }

        // Close the context when we're done
        ctx.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:LookAndFeel.java

public static void main(String[] args) {
    if (args.length == 0)
        usageError();// www.jav a  2s.c om
    if (args[0].equals("cross")) {
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (args[0].equals("system")) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (args[0].equals("motif")) {
        try {
            UIManager.setLookAndFeel("com.sun.java." + "swing.plaf.motif.MotifLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        usageError();
    // Note the look & feel must be set before
    // any components are created.
    run(new LookAndFeel(), 300, 200);
}

From source file:MethodTroubleToo.java

public static void main(String... args) {
    try {/*  w  ww . j av a 2 s.com*/
        MethodTroubleToo mtt = new MethodTroubleToo();
        Method m = MethodTroubleToo.class.getMethod("ping");

        switch (Integer.parseInt(args[0])) {
        case 0:
            m.invoke(mtt); // works
            break;
        case 1:
            m.invoke(mtt, null); // works (expect compiler warning)
            break;
        case 2:
            Object arg2 = null;
            m.invoke(mtt, arg2); // IllegalArgumentException
            break;
        case 3:
            m.invoke(mtt, new Object[0]); // works
            break;
        case 4:
            Object arg4 = new Object[0];
            m.invoke(mtt, arg4); // IllegalArgumentException
            break;
        default:
            System.out.format("Test not found%n");
        }

        // production code should handle these exceptions more gracefully
    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override//from  w ww  . j  a va  2  s  . c o m
        public void run() {
            try {
                Image img = null;
                img = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(new ImagePanel(img));
                frame.pack();
                frame.setVisible(true);
            } catch (Exception exp) {
                exp.printStackTrace();
            }
        }
    });
}

From source file:it.tidalwave.imageio.example.stats.FocalLengthStats.java

public static void main(final String[] args) {
    try {//from ww  w  .java  2s .c  o  m
        final PrintWriter out = new PrintWriter(new File(args[1]));
        new DirectoryWalker() {
            @Override
            protected void handleFile(final File file, final int depth, final Collection results)
                    throws IOException {
                if (file.getName().toUpperCase().endsWith(".NEF")) {
                    System.out.printf("Processing %s...\n", file.getCanonicalPath());
                    final ImageReader reader = (ImageReader) ImageIO.getImageReaders(file).next();
                    reader.setInput(ImageIO.createImageInputStream(file));
                    final IIOMetadata metadata = reader.getImageMetadata(0);
                    final NEFMetadata nefMetadata = (NEFMetadata) metadata;
                    final IFD exifIFD = nefMetadata.getExifIFD();
                    final TagRational focalLength = exifIFD.getFocalLength();
                    out.println(focalLength.doubleValue());
                }
            }

            public void start() throws IOException {
                super.walk(new File(args[0]), new ArrayList<Object>());
            }
        }.start();

        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dinstone.jrpc.NamespaceHandlerTest.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "application-context-sample.xml");

    HelloService service = (HelloService) applicationContext.getBean("rhsv1");
    try {// w w w.ja  v a  2 s. co m
        testHot(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.in.read();
    } catch (IOException e) {
    }

    applicationContext.close();
}

From source file:com.asual.summer.onejar.OneJarServer.java

public static void main(String[] args) throws Exception {
    Server server = new Server(Integer.valueOf(System.getProperty("server.port", "8080")));
    server.setHandler(new WebAppContext(getCurrentWarFile(), System.getProperty("server.contextPath", "/")));
    try {//w w w  .ja  v  a  2 s  .com
        server.start();
    } catch (Exception e) {
        server.stop();
        e.printStackTrace();
        System.exit(-1);
    }
}