Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:hu.sztaki.lpds.pgportal.services.dspace.LNIclient.java

/**
 * Optional main for standalone testing, demonstrate usage.
 *
 *//*w ww .j  a  v a  2s .  c om*/
public static void main(String[] argv) {
    // Args:  -G | -P  [ -i file ] [ -o file ] URL handle
    //         -e eperson -p password [ -t type ]
    Options options = new Options();
    options.addOption("h", "help", false, "show help message");
    options.addOption("o", "output", true, "output file for GET");
    options.addOption("i", "input", true, "input file for PUT");
    options.addOption("G", "get", false, "GET contents of Handle");
    options.addOption("P", "put", false, "PUT package into Handle");
    options.addOption("e", "eperson", true, "eperson to authenticate as (required)");
    options.addOption("p", "password", true, "password for eperson (required)");
    options.addOption("t", "type", true, "package type for GET/PUT");

    try {
        CommandLine line = (new PosixParser()).parse(options, argv);
        String eperson = line.getOptionValue("e");
        String password = line.getOptionValue("p");
        String type = line.getOptionValue("t");
        String rest[] = line.getArgs();
        if (eperson == null || password == null || rest.length < 2)
            Usage(options, 1, "Missing a required option or argument");

        String url = rest[0];
        String handle = rest[1];

        LNIclient lni = new LNIclient(url, eperson, password);
        if (type == null)
            type = "METS";

        if (line.hasOption("G")) {
            OutputStream pkg = System.out;
            if (line.hasOption("o"))
                pkg = new FileOutputStream(line.getOptionValue("o"));

            // TODO: add option to convey packager options here.
            try {
                InputStream g = lni.startGet(handle, type, null);
                copy(g, pkg);
                pkg.close();
            } finally {
                lni.finishGet();
            }
        } else if (line.hasOption("P")) {
            InputStream pkg = System.in;
            if (line.hasOption("i"))
                pkg = new FileInputStream(line.getOptionValue("i"));
            String result = lni.put(handle, type, null, pkg);
            System.err.println("LNI PUT created Handle: " + result);
        } else
            Usage(options, 1, "Missing required 'G' or 'P' option.");
    } catch (org.apache.commons.cli.ParseException pe) {
        Usage(options, 1, "Error in arguments: " + pe.toString());
    } catch (Throwable e) {
        System.err.println("Got exception: " + e.toString());
        e.printStackTrace();
    } finally {
        System.exit(0);
    }
}

From source file:com.intuit.tank.harness.APITestHarness.java

/**
 * @param args/*from  w  ww  . j a va 2 s.  c o  m*/
 */
public static void main(String[] args) {
    // set ttl on dns to small value
    try {
        java.security.Security.setProperty("networkaddress.cache.ttl", "0");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error setting dns timeout: " + e1.toString(), LogEventType.System));
    }
    try {
        System.setProperty("jsse.enableSNIExtension", "false");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error disabling SNI extension: " + e1.toString(), LogEventType.System));
    }
    if (args.length < 1) {
        usage();
        return;
    }
    getInstance().initializeFromArgs(args);

}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

/**
 * @param args//from  www .  j  av  a2  s  .  com
 */
public static void main(String[] args) {
    try {
        java.security.Security.setProperty("networkaddress.cache.ttl", "0");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error setting dns timeout: " + e1.toString(), LogEventType.System));
    }
    try {
        System.setProperty("jsse.enableSNIExtension", "false");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error disabling SNI extension: " + e1.toString(), LogEventType.System));
    }
    try {
        System.setProperty("jdk.certpath.disabledAlgorithms", "");
    } catch (Throwable e1) {
        System.err.println("Error setting property jdk.certpath.disabledAlgorithms: " + e1.toString());
        e1.printStackTrace();
    }
    String url = "";
    if (args.length > 0) {
        url = args[0];
    }
    Properties props = new Properties();
    try {
        InputStream configStream = AgentDebuggerFrame.class.getResourceAsStream("/log4j.properties");
        props.load(configStream);
        configStream.close();
    } catch (IOException e) {
        System.out.println("Error: Cannot laod configuration file ");
    }
    props.setProperty("log4j.appender.agent.File", "debugger.log");
    LogManager.resetConfiguration();
    PropertyConfigurator.configure(props);

    new AgentDebuggerFrame(true, url).setVisible(true);
}

From source file:Main.java

public static void showErrorMessage(Component parentComponent, String mensagem, Throwable t) {
    String errorMessage = t.toString();
    JOptionPane.showMessageDialog(parentComponent, mensagem + "\n" + errorMessage, "Erro",
            JOptionPane.ERROR_MESSAGE);
}

From source file:Main.java

private static String appendThrowable(String origin, Throwable tr) {
    String trMsg = tr == null ? "" : String.format(": %s", tr.toString());
    return String.format("%s%s", origin, trMsg);
}

From source file:Main.java

/**
 * Apply the toString() method recursively to this throwable and all its causes.
 * The idea is to get cause information as in printStackTrace() without the stack trace.
 *
 * @param t the throwable to print.//from  www  . j  a  va  2s . c o m
 * @return
 */
public static String getThrowableAndCausesAsString(Throwable t) {
    StringBuffer buf = new StringBuffer();
    buf.append(t.toString());
    if (t.getCause() != null) {
        buf.append("\nCaused by: ");
        buf.append(getThrowableAndCausesAsString(t.getCause()));
    }
    return buf.toString();
}

From source file:Main.java

public static void logThrowable(Throwable e) {
    if (DEBUG) {//  w  w  w .ja  v  a2s.c o m
        Log.e("LogUtil", e.toString());
        e.printStackTrace();
        if (LOG_TO_FILE) {
            logToFile(e);
        }
    }
}

From source file:Main.java

public static void logToFile(Throwable e) {
    try {//from w ww. jav  a 2s . c  o  m
        StringBuffer sb = new StringBuffer(e.toString() + "\n");
        StackTraceElement[] stElements = e.getStackTrace();
        String newLine = "";

        for (StackTraceElement stElement : stElements) {
            sb.append(newLine);
            sb.append("\tat ");
            sb.append(stElement.toString());
            newLine = "\n";
        }
    } catch (Exception ee) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static byte[] readELFHeadrIndentArray(File libFile) {
    if (libFile != null && libFile.exists()) {
        FileInputStream inputStream = null;
        try {/*w  w  w .  j  av a 2  s  . c  o m*/
            inputStream = new FileInputStream(libFile);
            if (inputStream != null) {
                byte[] tempBuffer = new byte[16];
                int count = inputStream.read(tempBuffer, 0, 16);
                if (count == 16) {
                    return tempBuffer;
                } else {
                    if (LOGENABLE) {
                        Log.e("readELFHeadrIndentArray",
                                "Error: e_indent lenght should be 16, but actual is " + count);
                    }
                }
            }
        } catch (Throwable t) {
            if (LOGENABLE) {
                Log.e("readELFHeadrIndentArray", "Error:" + t.toString());
            }
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    return null;
}

From source file:com.mobage.air.extension.Dispatcher.java

public static void dispatch(FREContext context, String eventType, Throwable exception) {
    try {/*ww  w .j  a  va  2  s  .c o m*/
        JSONArray args = new JSONArray();

        args.put(exception.toString());
        for (StackTraceElement item : exception.getStackTrace()) {
            args.put(item.toString());
        }

        context.dispatchStatusEventAsync(eventType, args.toString());
    } catch (Exception e) {
        Log.wtf(TAG, e);
    }
}