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.ebay.recommendations.RecommendationsSummary.java

/**
 * @param args//from   w  ww  .j  av  a 2  s  .  co  m
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    HttpClient client = new HttpClient();
    String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/recommendationsSummary";
    HttpMethod method = new GetMethod(fullUri);
    // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER
    method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>");
    method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US");

    method.addRequestHeader("Accept", "application/xml");

    try {
        client.executeMethod(method);
        String response = method.getResponseBodyAsString();
        System.out.println(response);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from www.  j  av  a 2 s .  c  om*/

        OutputStream os = new FileOutputStream("test.txt");

        InputStream is = new FileInputStream("test.txt");

        // write something
        os.write('A');

        // flush the stream but it does nothing
        os.flush();

        // write something else
        os.write('B');

        // read what we wrote
        System.out.println(is.available());
        os.close();
        is.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {/*from  w w  w  . j  a  va  2  s  .  c om*/

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, java.nio.charset.StandardCharsets.UTF_8);

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    CyclicBarrier barrier = new CyclicBarrier(2);
    new Thread() {
        @Override//  w ww. ja v a2 s .c om
        public void run() {
            try {
                System.out.println("in thread, before the barrier");
                barrier.await();
                System.out.println("in thread, after the barrier");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();

    try {
        System.out.println("main thread, before barrier");
        barrier.await();

        System.out.println("main thread, after barrier");
    } catch (Exception exc) {
        exc.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {//from   ww w  .j  a  va 2  s.com
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);
        writer.write(71);
        writer.write(72);

        // flush the stream
        writer.flush();

        // read what we write
        for (int i = 0; i < 3; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();

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

From source file:ConstructorDemo.java

/** 
 * Run the demo.//from   ww w  . j a  v a 2  s.c o  m
 *
 * @param args Command line arguments.
 */
public static void main(final String[] args) {
    try {
        final Class[] ARG_TYPES = new Class[] { String.class };

        Constructor cst = Integer.class.getConstructor(ARG_TYPES);

        System.out.println(cst.newInstance(new Object[] { "45" }));
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

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

        int port = 80;

        DatagramSocket ds = new DatagramSocket(port);

        byte buffer[] = new byte[BUFSIZE];

        while (true) {

            DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
            // Receive data
            ds.receive(dp);
            // Display address from the datagram packet
            InetAddress ia = dp.getAddress();
            System.out.println(ia);

            buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            dp.setData(buffer, 2, 5);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:CellPaddingLeadingPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {//from   w  w  w.  j a  v  a 2  s . c o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellPaddingLeadingPDF.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell;
        Paragraph p = new Paragraph(
                "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text ");
        table.addCell("default");
        table.addCell(p);
        table.addCell("padding 10");
        cell = new PdfPCell(p);
        cell.setPadding(10f);
        table.addCell(cell);
        table.addCell("no padding at all");
        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:CellBorderColorsWidthBackgroundPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/*from ww w.j a  v a  2s  . c o m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("CellBorderColorsWidthBackgroundPDF.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph("blue"));
        cell.setBorder(Rectangle.TOP);
        cell.setUseBorderPadding(true);
        cell.setBorderWidthTop(5f);
        cell.setBorderColorTop(Color.cyan);
        cell.setBackgroundColor(Color.blue);
        table.addCell(cell);

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

From source file:PdfActionGotoAnotherPdfFile.java

public static void main(String[] args) {
    Document document = new Document();
    Document remote = new Document();
    try {/*from  www . j  av  a 2 s.com*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("PdfActionGotoAnotherPdfFile.pdf"));
        PdfWriter.getInstance(remote, new FileOutputStream("PdfActionGotoAnotherPdfFileremote.pdf"));

        document.open();
        document.add(new Chunk("goto another document").setAction(
                PdfAction.gotoRemotePage("PdfActionGotoAnotherPdfFileremote.pdf", "test", false, true)));

        remote.open();
        remote.add(new Paragraph("Some remote document"));
        remote.newPage();
        Paragraph p = new Paragraph("This paragraph contains a ");
        p.add(new Chunk("local destination").setLocalDestination("test"));
        remote.add(p);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
    remote.close();
}