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:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {//from   w  w w .  ja v  a2s.c  o m

        PrintWriter pw = new PrintWriter(System.out);

        // write substrings
        pw.write(s, 0, 5);
        pw.write(s, 6, 5);

        // flush the writer
        pw.flush();

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

From source file:Main.java

public static void main(String[] args) {
    long c = 1234567890L;
    try {//from   ww w.  ja  v a2s  . co m

        PrintStream ps = new PrintStream(System.out);

        // print a long and change line
        ps.println(c);
        ps.print("from java2s.com");

        // flush the stream
        ps.flush();

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

From source file:be.anova.course.camel.beans.Main.java

public static void main(String[] args) {
    try {/*from  w  ww.j a v a  2 s .c  o  m*/
        ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
        Thread.sleep(60000);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String args[]) {
    try {// w ww. j a va 2  s  . c  o m

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket();

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);

        // Send the datagram packet
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {//from ww w .ja v a  2s.c  o m

        PrintWriter pw = new PrintWriter(System.out);

        // printf text with specified locale.
        // %s indicates a string will be placed there, which is s
        pw.printf(Locale.UK, "This is a %s program", s);

        // flush the writer
        pw.flush();

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

From source file:Main.java

public static void main(String[] args) {
    String destFile = "test.txt";

    try (BufferedWriter bw = new BufferedWriter(new FileWriter(destFile))) {
        bw.append("test");
        bw.newLine();/*from ww w. ja  v  a 2 s.  c o m*/
        bw.append("test1");
        bw.newLine();
        bw.append("test2");
        bw.newLine();
        bw.append("test3");

        bw.flush();
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}

From source file:AddingChunkToParagraphPDF.java

public static void main(String[] args) {
    try {//w w  w  . j  a  va  2 s .  c o  m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("AddingChunkToParagraphPDF.pdf"));
        document.open();
        Paragraph p = new Paragraph();
        p.add(new Chunk("Font.TIMES_ROMAN", new Font(Font.TIMES_ROMAN, 12)));
        document.add(new Paragraph(p));

        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  ww w  .  j av a 2s .  com*/
        // create a new process
        Process p = Runtime.getRuntime().exec("notepad.exe");

        // get the output stream
        OutputStream out = p.getOutputStream();

        // close the output stream
        System.out.println("Closing the output stream...");
        out.close();

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

}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {// w ww.j ava2s . c  o  m

        PrintWriter pw = new PrintWriter(System.out);

        // format text with specified locale.
        // %s indicates a string will be placed there, which is s
        pw.format(Locale.UK, "This is a %s program", s);

        // flush the writer
        pw.flush();

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

From source file:DocumentPageCountPDF.java

public static void main(String args[]) {
    try {//  w  w w.  java2  s  . c o m
        Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("DocumentPageCountPDF.pdf"));
        doc.open();

        Paragraph p = new Paragraph("text");

        doc.add(p);

        doc.close();
        System.out.println(writer.getPageNumber());
    } catch (Exception e) {
        e.printStackTrace();
    }
}