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:biz.bokhorst.xprivacy.Util.java

@SuppressLint("NewApi")
public static int getUserId(int uid) {
    int userId = 0;
    if (uid > 99) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
            try {
                // UserHandle: public static final int getUserId(int uid)
                Method method = (Method) UserHandle.class.getDeclaredMethod("getUserId", int.class);
                userId = (Integer) method.invoke(null, uid);
            } catch (Throwable ex) {
                Util.log(null, Log.WARN, ex.toString());
            }//  www  . ja v a  2 s  .c o  m
    } else
        userId = uid;
    return userId;
}

From source file:org.thoughtland.xlocation.Util.java

@SuppressLint("NewApi")
public static int getAppId(int uid) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        try {//from w w w .  ja  v a2  s .  c  o m
            // TODO: update by method in SDK 20
            // UserHandle: public static final int getAppId(int uid)
            Method method = (Method) UserHandle.class.getDeclaredMethod("getAppId", int.class);
            uid = (Integer) method.invoke(null, uid);
        } catch (Throwable ex) {
            Util.log(null, Log.WARN, ex.toString());
        }
    return uid;
}

From source file:io.uploader.drive.drive.DriveOperations.java

private static void dealWithException(Throwable e, AtomicInteger counter) throws Throwable {
    if (isRetryable(e)) {
        if (counter.getAndIncrement() >= maxNumberOfRetry) {
            throw e;
        }/*w w w . ja v  a 2 s .c  o m*/
        logger.info(String.format("Error: %s", e.toString()));
    } else
        throw e;
}

From source file:org.thoughtland.xlocation.Util.java

@SuppressLint("NewApi")
public static int getUserId(int uid) {
    int userId = 0;
    if (uid > 99) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
            try {
                // TODO: update by method in SDK 20
                // UserHandle: public static final int getUserId(int uid)
                Method method = (Method) UserHandle.class.getDeclaredMethod("getUserId", int.class);
                userId = (Integer) method.invoke(null, uid);
            } catch (Throwable ex) {
                Util.log(null, Log.WARN, ex.toString());
            }/*from   w w  w. j a  v a 2 s.  co m*/
    } else
        userId = uid;
    return userId;
}

From source file:lcmc.LCMC.java

/** Inits the application. */
protected static String initApp(final String[] args) {
    try {// w  w  w .  jav  a 2  s .co m
        /* Metal */
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        MetalLookAndFeel.setCurrentTheme(new OceanTheme() {
            /** e.g. arrows on split pane... */
            protected ColorUIResource getPrimary1() {
                return new ColorUIResource(ClusterBrowser.STATUS_BACKGROUND);
            }

            /** unknown to me */
            protected ColorUIResource getPrimary2() {
                return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND);
            }

            /** unknown to me */
            protected ColorUIResource getPrimary3() {
                return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND);
            }

            /** Button and other borders. */
            protected ColorUIResource getSecondary1() {
                return new ColorUIResource(AppDefaults.BACKGROUND_DARK);
            }

            protected ColorUIResource getSecondary2() {
                return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND);
            }

            /** Split pane divider. Line in the main menu. */
            protected ColorUIResource getSecondary3() {
                return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND);
            }
        });
    } catch (final Exception e) {
        /* ignore it then */
    }
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(final Thread t, final Throwable ex) {
            Tools.appError("uncaught exception", ex.toString(), (Exception) ex);
        }
    });
    float fps = 20.0f;
    final Options options = new Options();

    options.addOption("h", HELP_OP, false, "print this help");
    options.addOption(null, KEEP_HELPER_OP, false, "do not overwrite the lcmc-gui-helper program");
    options.addOption(null, RO_OP, false, "read only mode");
    options.addOption(null, OP_OP, false, "operator mode");
    options.addOption(null, ADMIN_OP, false, "administrator mode");
    options.addOption(null, OP_MODE_OP, true, "operating mode. <arg> can be:\n" + "ro - read only\n"
            + "op - operator\n" + "admin - administrator");
    options.addOption(null, NOLRM_OP, false, "do not show removed resources from LRM.");
    options.addOption(null, "auto", true, "for testing");
    options.addOption("v", VERSION_OP, false, "print version");
    options.addOption(null, AUTO_OP, true, "for testing");
    options.addOption(null, NO_UPGRADE_CHECK_OP, false, "disable upgrade check");
    options.addOption(null, NO_PLUGIN_CHECK_OP, false,
            "disable plugin check, DEPRECATED: there are no plugins");
    options.addOption(null, TIGHTVNC_OP, false, "enable tight vnc viewer");
    options.addOption(null, ULTRAVNC_OP, false, "enable ultra vnc viewer");
    options.addOption(null, REALVNC_OP, false, "enable real vnc viewer");
    options.addOption(null, BIGDRBDCONF_OP, false,
            "create one big drbd.conf, instead of many" + " files in drbd.d/ directory");
    options.addOption(null, STAGING_DRBD_OP, false, "enable more DRBD installation options");
    options.addOption(null, STAGING_PACEMAKER_OP, false, "enable more Pacemaker installation options");
    options.addOption(null, VNC_PORT_OFFSET_OP, true, "offset for port forwarding");
    options.addOption(null, SLOW_OP, false, "specify this if you have slow computer");
    options.addOption(null, RESTORE_MOUSE_OP, false, "for testing");
    options.addOption(null, SCALE_OP, true, "scale fonts and sizes of elements in percent (100)");
    options.addOption(null, ID_DSA_OP, true, "location of id_dsa file ($HOME/.ssh/id_dsa)");
    options.addOption(null, ID_RSA_OP, true, "location of id_rsa file ($HOME/.ssh/id_rsa)");
    options.addOption(null, KNOWN_HOSTS_OP, true, "location of known_hosts file ($HOME/.ssh/known_hosts)");
    options.addOption(null, OUT_OP, true, "where to redirect the standard out");
    options.addOption(null, DEBUG_OP, true, "debug level, 0 - none, 3 - all");
    options.addOption("c", CLUSTER_OP, true, "define a cluster");
    final Option hostOp = new Option("h", HOST_OP, true, "define a cluster, used with --cluster option");
    hostOp.setArgs(10000);
    options.addOption(hostOp);
    options.addOption(null, SUDO_OP, false, "whether to use sudo, used with --cluster option");
    options.addOption(null, USER_OP, true, "user to use with sudo, used with --cluster option");
    options.addOption(null, PORT_OP, true, "ssh port, used with --cluster option");
    options.addOption(null, ADVANCED_OP, false, "start in an advanced mode");
    options.addOption(null, ONE_HOST_CLUSTER_OP, false, "allow one host cluster");
    final CommandLineParser parser = new PosixParser();
    String autoArgs = null;
    try {
        final CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption(OUT_OP)) {
            final String out = cmd.getOptionValue(OUT_OP);
            if (out != null) {
                try {
                    System.setOut(new PrintStream(new FileOutputStream(out)));
                } catch (final FileNotFoundException e) {
                    System.exit(2);
                }
            }
        }
        if (cmd.hasOption(DEBUG_OP)) {
            final String level = cmd.getOptionValue(DEBUG_OP);
            if (level != null && Tools.isNumber(level)) {
                Tools.setDebugLevel(Integer.parseInt(level));
            } else {
                throw new ParseException("cannot parse debug level: " + level);
            }
        }
        boolean tightvnc = cmd.hasOption(TIGHTVNC_OP);
        boolean ultravnc = cmd.hasOption(ULTRAVNC_OP);
        final boolean realvnc = cmd.hasOption(REALVNC_OP);
        if (!tightvnc && !ultravnc && !realvnc) {
            if (Tools.isLinux()) {
                tightvnc = true;
            } else if (Tools.isWindows()) {
                ultravnc = true;
            } else {
                tightvnc = true;
                ultravnc = true;
            }
        }
        boolean advanced = cmd.hasOption(ADVANCED_OP);
        Tools.getConfigData().setAdvancedMode(advanced);
        Tools.getConfigData().setTightvnc(tightvnc);
        Tools.getConfigData().setUltravnc(ultravnc);
        Tools.getConfigData().setRealvnc(realvnc);

        Tools.getConfigData().setUpgradeCheckEnabled(!cmd.hasOption(NO_UPGRADE_CHECK_OP));
        Tools.getConfigData().setBigDRBDConf(cmd.hasOption(BIGDRBDCONF_OP));
        Tools.getConfigData().setStagingDrbd(cmd.hasOption(STAGING_DRBD_OP));
        Tools.getConfigData().setStagingPacemaker(cmd.hasOption(STAGING_PACEMAKER_OP));
        Tools.getConfigData().setNoLRM(cmd.hasOption(NOLRM_OP));
        Tools.getConfigData().setKeepHelper(cmd.hasOption(KEEP_HELPER_OP));
        Tools.getConfigData().setOneHostCluster(cmd.hasOption(ONE_HOST_CLUSTER_OP));
        final String pwd = System.getProperty("user.home");
        final String scaleOp = cmd.getOptionValue(SCALE_OP, "100");
        try {
            final int scale = Integer.parseInt(scaleOp);
            Tools.getConfigData().setScale(scale);
            Tools.resizeFonts(scale);
        } catch (java.lang.NumberFormatException e) {
            Tools.appWarning("cannot parse scale: " + scaleOp);
        }

        final String idDsaPath = cmd.getOptionValue(ID_DSA_OP, pwd + "/.ssh/id_dsa");
        final String idRsaPath = cmd.getOptionValue(ID_RSA_OP, pwd + "/.ssh/id_rsa");
        final String knownHostsPath = cmd.getOptionValue(KNOWN_HOSTS_OP, pwd + "/.ssh/known_hosts");
        Tools.getConfigData().setIdDSAPath(idDsaPath);
        Tools.getConfigData().setIdRSAPath(idRsaPath);
        Tools.getConfigData().setKnownHostPath(knownHostsPath);

        final String opMode = cmd.getOptionValue(OP_MODE_OP);
        autoArgs = cmd.getOptionValue(AUTO_OP);
        if (cmd.hasOption(HELP_OP)) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar LCMC.jar [OPTIONS]", options);
            System.exit(0);
        }
        if (cmd.hasOption(VERSION_OP)) {
            System.out.println("LINUX CLUSTER MANAGEMENT CONSOLE " + Tools.getRelease() + " by Rasto Levrinc");
            System.exit(0);
        }
        if (cmd.hasOption("ro") || "ro".equals(opMode)) {
            Tools.getConfigData().setAccessType(ConfigData.AccessType.RO);
            Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.RO);
        } else if (cmd.hasOption("op") || "op".equals(opMode)) {
            Tools.getConfigData().setAccessType(ConfigData.AccessType.OP);
            Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.OP);
        } else if (cmd.hasOption("admin") || "admin".equals(opMode)) {
            Tools.getConfigData().setAccessType(ConfigData.AccessType.ADMIN);
            Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.ADMIN);
        } else if (opMode != null) {
            Tools.appWarning("unknown operating mode: " + opMode);
        }
        if (cmd.hasOption(SLOW_OP)) {
            fps = fps / 2;
        }
        if (cmd.hasOption(RESTORE_MOUSE_OP)) {
            /* restore mouse if it is stuck in pressed state, during
             * robot tests. */
            RoboTest.restoreMouse();
        }
        final String vncPortOffsetString = cmd.getOptionValue(VNC_PORT_OFFSET_OP);
        if (vncPortOffsetString != null && Tools.isNumber(vncPortOffsetString)) {
            Tools.getConfigData().setVncPortOffset(Integer.parseInt(vncPortOffsetString));
        }
        Tools.getConfigData().setAnimFPS(fps);
        if (cmd.hasOption(CLUSTER_OP) || cmd.hasOption(HOST_OP)) {
            parseClusterOptions(cmd);
        }
    } catch (ParseException exp) {
        System.out.println("ERROR: " + exp.getMessage());
        System.exit(1);
    }
    Tools.debug(null, "max mem: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "m", 1);
    return autoArgs;
}

From source file:com.mpower.clientcollection.utilities.WebUtils.java

/**
 * Common method for returning a parsed xml document given a url and the
 * http context and client objects involved in the web connection.
 *
 * @param urlString//from w  w w  . jav a  2s  .c  o  m
 * @param localContext
 * @param httpclient
 * @return
 */
public static DocumentFetchResult getXmlDocument(String urlString, HttpContext localContext,
        HttpClient httpclient) {
    URI u = null;
    try {
        URL url = new URL(urlString);
        u = url.toURI();
    } catch (Exception e) {
        e.printStackTrace();
        return new DocumentFetchResult(e.getLocalizedMessage()
                // + app.getString(R.string.while_accessing) + urlString);
                + ("while accessing") + urlString, 0);
    }

    if (u.getHost() == null) {
        return new DocumentFetchResult("Invalid server URL (no hostname): " + urlString, 0);
    }

    // if https then enable preemptive basic auth...
    if (u.getScheme().equals("https")) {
        enablePreemptiveBasicAuth(localContext, u.getHost());
    }

    // set up request...
    HttpGet req = WebUtils.createOpenRosaHttpGet(u);
    //req.addHeader(WebUtils.ACCEPT_ENCODING_HEADER, WebUtils.GZIP_CONTENT_ENCODING);

    HttpResponse response = null;
    try {
        response = httpclient.execute(req, localContext);
        int statusCode = response.getStatusLine().getStatusCode();

        HttpEntity entity = response.getEntity();

        if (statusCode != HttpStatus.SC_OK) {
            WebUtils.discardEntityBytes(response);
            if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
                // clear the cookies -- should not be necessary?
                ClientCollection.getInstance().getCookieStore().clear();
            }
            String webError = response.getStatusLine().getReasonPhrase() + " (" + statusCode + ")";

            return new DocumentFetchResult(u.toString() + " responded with: " + webError, statusCode);
        }

        if (entity == null) {
            String error = "No entity body returned from: " + u.toString();
            Log.e(t, error);
            return new DocumentFetchResult(error, 0);
        }

        if (!entity.getContentType().getValue().toLowerCase(Locale.ENGLISH)
                .contains(WebUtils.HTTP_CONTENT_TYPE_TEXT_XML)) {
            WebUtils.discardEntityBytes(response);
            String error = "ContentType: " + entity.getContentType().getValue() + " returned from: "
                    + u.toString()
                    + " is not text/xml.  This is often caused a network proxy.  Do you need to login to your network?";
            Log.e(t, error);
            return new DocumentFetchResult(error, 0);
        }
        // parse response
        Document doc = null;
        try {
            InputStream is = null;
            InputStreamReader isr = null;
            try {
                is = entity.getContent();
                Header contentEncoding = entity.getContentEncoding();
                if (contentEncoding != null
                        && contentEncoding.getValue().equalsIgnoreCase(WebUtils.GZIP_CONTENT_ENCODING)) {
                    is = new GZIPInputStream(is);
                }
                isr = new InputStreamReader(is, "UTF-8");
                doc = new Document();
                KXmlParser parser = new KXmlParser();
                parser.setInput(isr);
                parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
                doc.parse(parser);
                isr.close();
                isr = null;
            } finally {
                if (isr != null) {
                    try {
                        // ensure stream is consumed...
                        final long count = 1024L;
                        while (isr.skip(count) == count)
                            ;
                    } catch (Exception e) {
                        // no-op
                    }
                    try {
                        isr.close();
                    } catch (Exception e) {
                        // no-op
                    }
                }
                if (is != null) {
                    try {
                        is.close();
                    } catch (Exception e) {
                        // no-op
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            String error = "Parsing failed with " + e.getMessage() + "while accessing " + u.toString();
            Log.e(t, error);
            return new DocumentFetchResult(error, 0);
        }

        boolean isOR = false;
        Header[] fields = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER);
        if (fields != null && fields.length >= 1) {
            isOR = true;
            boolean versionMatch = false;
            boolean first = true;
            StringBuilder b = new StringBuilder();
            for (Header h : fields) {
                if (WebUtils.OPEN_ROSA_VERSION.equals(h.getValue())) {
                    versionMatch = true;
                    break;
                }
                if (!first) {
                    b.append("; ");
                }
                first = false;
                b.append(h.getValue());
            }
            if (!versionMatch) {
                Log.w(t, WebUtils.OPEN_ROSA_VERSION_HEADER + " unrecognized version(s): " + b.toString());
            }
        }
        return new DocumentFetchResult(doc, isOR);
    } catch (Exception e) {
        clearHttpConnectionManager();
        e.printStackTrace();
        String cause;
        Throwable c = e;
        while (c.getCause() != null) {
            c = c.getCause();
        }
        cause = c.toString();
        String error = "Error: " + cause + " while accessing " + u.toString();

        Log.w(t, error);
        return new DocumentFetchResult(error, 0);
    }
}

From source file:cn.kk.exia.MangaDownloader.java

public final static HttpURLConnection getUrlConnection(final String url, final boolean post,
        final String output) throws IOException {
    int retries = 0;
    HttpURLConnection conn;/* w  w  w . j  ava  2 s.c  om*/
    while (true) {
        try {
            final URL urlObj = new URL(url);
            conn = (HttpURLConnection) urlObj.openConnection();
            conn.setConnectTimeout(15000);
            conn.setReadTimeout(30000);
            if (post) {
                conn.setRequestMethod("POST");
            }
            final String referer;
            final int pathIdx;
            if ((pathIdx = url.lastIndexOf('/')) > "https://".length()) {
                referer = url.substring(0, pathIdx);
            } else {
                referer = url;
            }
            conn.setRequestProperty("Referer", referer);
            final Set<String> keys = MangaDownloader.DEFAULT_CONN_HEADERS.keySet();
            for (final String k : keys) {
                final String value = MangaDownloader.DEFAULT_CONN_HEADERS.get(k);
                if (value != null) {
                    conn.setRequestProperty(k, value);
                }
            }
            // conn.setUseCaches(false);
            if (output != null) {
                conn.setDoOutput(true);
                final BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream());
                out.write(output.getBytes(MangaDownloader.CHARSET_UTF8));
                out.close();
            }
            if (MangaDownloader.appendCookies(MangaDownloader.cookie, conn)) {
                MangaDownloader.putConnectionHeader("Cookie", MangaDownloader.cookie.toString());
            }
            break;
        } catch (final Throwable e) {
            // 
            System.err.println(e.toString());
            if (retries++ > 10) {
                throw new IOException(e);
            } else {
                try {
                    Thread.sleep((60 * retries * MangaDownloader.sleepBase)
                            + ((int) Math.random() * MangaDownloader.sleepBase * 60 * retries));
                } catch (final InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    return conn;
}

From source file:com.alibaba.jstorm.yarn.utils.JstormYarnUtils.java

public static String stringify(Throwable t) {
    StringWriter sw = new StringWriter();
    sw.append(t.toString()).append('\n');
    t.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:org.ambraproject.admin.action.AdminTopAction.java

/**
 * Extract the message string from an exception object.
 *
 * @param t The throwable containing the message that will be extracted.
 * @return message string// w  ww  .j  a  v  a  2  s  . c  o m
 */
private static String getMessages(Throwable t) {
    StringBuilder msg = new StringBuilder();
    while (t != null) {
        msg.append(t.toString());
        t = t.getCause();
        if (t != null)
            msg.append("<br/>\n");
    }
    return msg.toString();
}

From source file:com.zimbra.cs.datasource.DataSourceManager.java

private static String generateErrorMessage(Throwable t) {
    StringBuilder buf = new StringBuilder();
    while (t != null) {
        // HACK: go with JavaMail error message
        if (t.getClass().getName().startsWith("javax.mail.")) {
            String msg = t.getMessage();
            return msg != null ? msg : t.toString();
        }/* ww w  .  jav  a 2s . c o  m*/
        if (buf.length() > 0) {
            buf.append(", ");
        }
        String msg = t.getMessage();
        buf.append(msg != null ? msg : t.toString());
        t = t.getCause();
    }
    return buf.toString();
}