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.cm.util.SendEmail.java

public static void main(String args[]) {
    try {/*www .  ja v  a  2  s  .c  om*/
        Email email = new Email();
        email.setEmailAddress("lawale4me@yahoo.com");
        email.setSubject("Your have create a new Case :");
        email.setMessage("Case Body" + "\n " + Log.APPURL);
        System.out.println("about to send");
        new SendEmail().sendSimpleMail(email);
        System.out.println("sent");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:BooleanAndOr.java

public static void main(String[] a) {
    String s = null;//from   w  w  w.  j  ava 2  s.  co  m

    // These use the conventional logical "and" (&&) and "or" (||).
    try {
        if ((s != null) && (s.length() > 0))
            System.out.println("At Point One");
        if ((s != null) || (s.length() > 0))
            System.out.println("At Point Two");
    } catch (Exception e) {
        System.out.print("Logical section threw ");
        e.printStackTrace();
    }

    // These use bitwise "and" (&) and "or" (|); is it valid? What results?
    try {
        if ((s == null) & (s.length() > 0))
            System.out.println("At Point Three");
        if ((s == null) | (s.length() > 0))
            System.out.println("At Point Four");
    } catch (Exception e) {
        System.out.print("Bitwise section threw ");
        e.printStackTrace();
    }
}

From source file:GetAllAttrs.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 {/*from w w w  .j  av a2s  .  com*/
        // Create the initial context
        DirContext ctx = new InitialDirContext(env);

        // Get all the attributes of named object
        Attributes answer = ctx.getAttributes("cn=Ted Geisel, ou=People");

        // Print the answer
        printAttrs(answer);

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

From source file:MainClass.java

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

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

        while (resultSet.next()) {
            printEmployee(resultSet);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
    }
}

From source file:koper.demo.performance.SendDataEventMsgPerf.java

/**
 * DataEventMsg ?/*from  w ww. j  a  va2  s.  co  m*/
 * @param args ?:???
 *             ?:?????? sleep 
 */
public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml",
            "kafka/context-data-producer.xml");

    Order order = new Order();
    order.setId(100);
    order.setOrderNo("order_no");
    order.setCreatedTime("oroder_created_time");

    OrderService orderService = (OrderService) context.getBean("orderServiceImpl");

    int threadNum = 1;
    long sleepMs = 1000L;
    if (args.length >= 1) {
        threadNum = Integer.parseInt(args[0]);
        sleepMs = Long.parseLong(args[1]);
    }
    final long finalSleepMs = sleepMs;
    ExecutorService executorService = Executors.newFixedThreadPool(threadNum);
    for (int i = 0; i < threadNum; ++i) {
        executorService.execute(() -> {
            while (true) {
                orderService.insertOrder(order);
                try {
                    Thread.sleep(finalSleepMs);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

From source file:com.predic8.membrane.core.RouterCLI.java

public static void main(String[] args) throws ParseException {

    MembraneCommandLine cl = new MembraneCommandLine();
    cl.parse(args);/* www.  j ava  2 s .c  om*/
    if (cl.needHelp()) {
        cl.printUsage();
        return;
    }

    try {
        Router.init(getConfigFile(cl), RouterCLI.class.getClassLoader()).getConfigurationManager()
                .loadConfiguration(getRulesFile(cl));
        //System.out.println("preloading cache...");
        //ApplicationCachePreLoader.init();
    } catch (ClassNotFoundException e) {

        e.printStackTrace();

    } catch (PortOccupiedException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(
                "Could not read rules configuration. Please specify a file containing rules using the -c command line option. Or make sure that the file "
                        + System.getenv("MEMBRANE_HOME") + "/conf/rules.xml exists");
        System.exit(1);
    }

    new RouterCLI().waitForever();

}

From source file:com.sonarsource.cobol.ebcdic.FileConverterTest.java

public static void main(String[] args) {
    FileConverter converter = new FileConverter(Charset.forName("UTF-8"), Charset.forName("UTF-8"));
    StringWriter writer = new StringWriter();
    try {//from  w  ww .j a  v a  2 s.co  m
        converter.convert("This is a " + (char) 0x15 + " new line", writer);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SearchSubtree.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 {//from w  ww  .ja  v a2s  . co m
        // Create initial context
        DirContext ctx = new InitialDirContext(env);

        // Specify the ids of the attributes to return
        String[] attrIDs = { "sn", "telephonenumber", "golfhandicap", "mail" };
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes(attrIDs);
        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        // Specify the search filter to match
        // Ask for objects with attribute sn == Geisel and which have
        // the "mail" attribute.
        String filter = "(&(sn=Geisel)(mail=*))";

        // Search subtree for objects using filter
        NamingEnumeration answer = ctx.search("", filter, ctls);

        // Print the answer
        // Search.printSearchEnumeration(answer);

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

From source file:MainClass.java

public static void main(String[] args) {
    ExecutorService application = Executors.newFixedThreadPool(2);

    Buffer sharedLocation = new UnsynchronizedBuffer();

    System.out.println("Action\t\tValue\tProduced\tConsumed");
    System.out.println("------\t\t-----\t--------\t--------\n");

    try {/*from   w  ww . j av a  2s . c  o  m*/
        application.execute(new Producer(sharedLocation));
        application.execute(new Consumer(sharedLocation));
    } catch (Exception exception) {
        exception.printStackTrace();
    }

    application.shutdown(); // terminate application when threads end
}

From source file:SearchObject.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 {//ww w  .ja va 2s  .com
        // Create initial context
        DirContext ctx = new InitialDirContext(env);

        // Specify the ids of the attributes to return
        String[] attrIDs = { "sn", "telephonenumber", "golfhandicap", "mail" };
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes(attrIDs);
        ctls.setSearchScope(SearchControls.OBJECT_SCOPE);

        // Specify the search filter to match
        // Ask for objects with attribute sn == Geisel and which have
        // the "mail" attribute.
        String filter = "(&(sn=Geisel)(mail=*))";

        // Search subtree for objects using filter
        NamingEnumeration answer = ctx.search("cn=Ted Geisel, ou=People", filter, ctls);

        // Print the answer
        // Search.printSearchEnumeration(answer);

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