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 destFile = "primitives.dat";

    try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(destFile))) {
        dos.writeInt(765);//  www  .j  ava2  s.  c om
        dos.writeDouble(6789.50);
        dos.writeBoolean(true);
        dos.writeUTF("Java Input/Output  is cool!");

        dos.flush();

        System.out.println("Data has  been  written to " + (new File(destFile)).getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    long x = 1234567890l;
    try {//  ww  w  . ja  v  a2 s .c o  m

        PrintStream ps = new PrintStream(System.out);

        // print long
        ps.print(x);

        // flush the stream
        ps.flush();

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

From source file:Main.java

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

    try (PushbackInputStream pis = new PushbackInputStream(new FileInputStream(srcFile))) {
        byte byteData;
        while ((byteData = (byte) pis.read()) != -1) {
            System.out.print((char) byteData);
            pis.unread(byteData);/*from   www  .j ava2 s. co  m*/
            // Reread the byte we unread
            byteData = (byte) pis.read();
            System.out.print((char) byteData);
        }
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}

From source file:com.rapleaf.api.personalization.RapleafExample.java

public static void main(String[] args) {
    RapleafApi api = new RapleafApi("SET_ME"); // Set API key here
    try {/*from   w w w. j a  v  a  2s  .  c o  m*/
        JSONObject response = api.queryByEmail("dummy@rapleaf.com", true);
        System.out.println(response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {//from   w  ww .j a v  a 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);
        ds.setSoTimeout(1000);
        ds.send(dp);

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

From source file:Main.java

public static void main(String args[]) {
    try {/*from  ww  w.j  av a2s. 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);
        ds.setSendBufferSize(1000);
        ds.send(dp);

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

From source file:Main.java

public static void main(String[] args) {
    File fileObject = new File("person.ser");

    try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileObject))) {

        Person p1 = (Person) ois.readObject();
        Person p2 = (Person) ois.readObject();
        Person p3 = (Person) ois.readObject();

        System.out.println(p1);/*from   www  .  j  a v a  2 s .c om*/
        System.out.println(p2);
        System.out.println(p3);

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

From source file:Main.java

public static void main(String args[]) {
    try {//from   ww w. ja  va  2 s.co  m
        String s1 = "-99,20";
        System.out.println(getNumber(s1));

        s1 = "1,4";
        System.out.println(getNumber(s1));
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String args[]) {
    try {//from w  ww  .ja va2  s  . co 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);
        ds.setReuseAddress(true);
        ds.send(dp);

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

From source file:ChainedActionsPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  w w w .ja v  a  2 s .  com
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ChainedActionsPDF.pdf"));
        document.open();
        PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
        action.next(new PdfAction("http://www.java2s.com"));
        Paragraph p = new Paragraph(new Chunk("Click to go to a website").setAction(action));
        document.add(p);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}