Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static void main(String[] args) {

    try {// w  ww.ja v  a2 s. com
        String str1 = "java2s.com";
        System.out.println("string1 = " + str1);
        // copy the contents of the String to a byte array
        byte[] arr = str1.getBytes("ASCII");

        String str2 = new String(arr);
        System.out.println("new string = " + str2);
    } catch (Exception e) {
        System.out.print(e.toString());
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {// w  w  w  .j  a va2 s.  c o  m
        String str1 = "java2s.com";
        System.out.println("string1 = " + str1);
        // copy the contents of the String to a byte array
        byte[] arr = str1.getBytes(Charset.forName("ASCII"));

        String str2 = new String(arr);
        System.out.println("new string = " + str2);
    } catch (Exception e) {
        System.out.print(e.toString());
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    String input = null;/*from   www.  ja v a 2  s .  c om*/
    try {
        String capitalized = capitalize(input);
        System.out.println(capitalized);
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {//  w  ww . j a v  a2 s. co  m
        MyClass c = new MyClass();
        Class cls = c.getClass();

        Field lVal = cls.getDeclaredField("l");
        System.out.println("Field = " + lVal.toString());
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {//w  w w .j a  v a  2 s  .co  m
        MyClass c = new MyClass();
        Class cls = c.getClass();

        // returns the array of Field objects
        Field[] fields = cls.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            System.out.println("Field = " + fields[i].toString());
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:MainClass.java

public static void main(String[] arguments) {
    String data = "jdbc:odbc:YourSettings";
    try {/*from  w w  w  . jav  a 2 s .c om*/
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conn = DriverManager.getConnection(data, "", "");
        Statement st = conn.createStatement();
        ResultSet rec = st
                .executeQuery("SELECT * FROM Coal WHERE (Country='" + arguments[0] + "') ORDER BY Year");
        while (rec.next()) {
            System.out.println(rec.getString(1) + "\t" + rec.getString(2) + "\t\t" + rec.getString(3) + "\t"
                    + rec.getString(4));
        }
        st.close();
    } catch (Exception e) {
        System.out.println("Error: " + e.toString() + e.getMessage());
    }
}

From source file:ObjectReader.java

public static void main(String[] arguments) {
    try {//from w  w  w. j  a  v a 2  s  .  c  o  m
        FileInputStream fi = new FileInputStream("message.obj");
        ObjectInputStream oi = new ObjectInputStream(fi);
        Message mess = (Message) oi.readObject();
        System.out.println("Message:\n");
        System.out.println("From: " + mess.from);
        System.out.println("To: " + mess.to);
        System.out.println("Date: " + mess.when + "\n");
        for (int i = 0; i < mess.lineCount; i++)
            System.out.println(mess.text[i]);
        oi.close();
    } catch (Exception e) {
        System.out.println("Error " + e.toString());
    }
}

From source file:AllCapsDemo.java

License:asdf

public static void main(String[] arguments) {
    String sourceName = "asdf";
    try {/*www .  j  a va 2  s.c om*/
        File source = new File(sourceName);
        File temp = new File("cap" + sourceName + ".tmp");

        FileReader fr = new FileReader(source);
        BufferedReader in = new BufferedReader(fr);

        FileWriter fw = new FileWriter(temp);
        BufferedWriter out = new BufferedWriter(fw);

        boolean eof = false;
        int inChar = 0;
        do {
            inChar = in.read();
            if (inChar != -1) {
                char outChar = Character.toUpperCase((char) inChar);
                out.write(outChar);
            } else
                eof = true;
        } while (!eof);
        in.close();
        out.close();

        boolean deleted = source.delete();
        if (deleted)
            temp.renameTo(source);
    } catch (Exception se) {
        System.out.println("Error - " + se.toString());
    }
}

From source file:JAXPTransletOneTransformation.java

public static void main(String argv[]) throws TransformerException, TransformerConfigurationException,
        IOException, SAXException, ParserConfigurationException, FileNotFoundException {
    // Set the TransformerFactory system property to generate and use a translet.
    // Note: To make this sample more flexible, load properties from a properties file.    
    // The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
    String key = "javax.xml.transform.TransformerFactory";
    String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
    Properties props = System.getProperties();
    props.put(key, value);//from w w w.  j  av a 2s  .com
    System.setProperties(props);

    String xslInURI = "todo.xsl";
    String xmlInURI = "todo.xml";
    String htmlOutURI = "todo.html";
    try {
        // Instantiate the TransformerFactory, and use it along with a SteamSource
        // XSL stylesheet to create a Transformer.
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(new StreamSource(xslInURI));
        // Perform the transformation from a StreamSource to a StreamResult;
        transformer.transform(new StreamSource(xmlInURI), new StreamResult(new FileOutputStream(htmlOutURI)));
        System.out.println("Produced todo.html");
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
}

From source file:MainClass.java

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

    Certificate[] certpath = new Certificate[args.length - 1];
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    int i;// www .  ja v  a 2 s.  c  o  m
    for (i = 0; i < args.length - 1; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        certpath[i] = cf.generateCertificate(in);
    }
    FileInputStream in = new FileInputStream(args[i]);
    Certificate trust = cf.generateCertificate(in);

    boolean pass = false;
    String reason = "";
    for (i = 0; i < certpath.length; i++) {
        try {
            PublicKey pbk;
            if (i == certpath.length - 1) {
                pbk = trust.getPublicKey();
            } else {
                pbk = certpath[i + 1].getPublicKey();
            }
            certpath[i].verify(pbk);
            pass = true;
        } catch (Exception e) {
            pass = false;
            reason += i + "  " + e.toString();
            break;
        }
    }
    System.out.println(pass);
}