Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.aw.support.reflection.MethodInvoker.java

/**
 * Invoke specific method on the target and returns the value that this method returns
 *
 * @param target//w  w w  . j  av  a  2 s .  c om
 * @param methodName
 * @return
 */
public static Object invoke(Object target, String methodName) throws Throwable {
    Object objectToReturn = null;
    try {
        Class cls = target.getClass();
        Method method = cls.getMethod(methodName, null);
        objectToReturn = method.invoke(target, null);
    } catch (Throwable e) {
        logger.error("Cannot execute class:" + target.getClass() + "method :" + methodName);
        Throwable cause = e.getCause();
        if ((cause instanceof FlowBreakSilentlyException) || (cause instanceof AWException)) {
            throw cause;
        }
        e.printStackTrace();
        throw e;
    }
    return objectToReturn;
}

From source file:edu.samplu.common.WebDriverUtil.java

public static void highlightElement(WebDriver webDriver, WebElement webElement) {
    if (jsHighlightEnabled) {
        try {//from w  ww.  j av  a  2s  .  co  m
            //                System.out.println("highlighting " + webElement.toString() + " on url " + webDriver.getCurrentUrl());
            JavascriptExecutor js = (JavascriptExecutor) webDriver;
            js.executeScript("element = arguments[0];\n" + "originalStyle = element.getAttribute('style');\n"
                    + "element.setAttribute('style', originalStyle + \"; background: " + JS_HIGHLIGHT_BACKGROUND
                    + "; border: 2px solid " + JS_HIGHLIGHT_BOARDER + ";\");\n" + "setTimeout(function(){\n"
                    + "    element.setAttribute('style', originalStyle);\n" + "}, "
                    + System.getProperty(JS_HIGHLIGHT_MS_PROPERTY, JS_HIGHLIGHT_MS + "") + ");", webElement);
        } catch (Throwable t) {
            System.out.println("Throwable during javascript highlight element");
            t.printStackTrace();
        }
    }
}

From source file:com.leclercb.taskunifier.gui.main.Main.java

private static void secondaryMain(String[] args) {
    try {//from w w w.j  a v  a  2 s  .  co m
        loadSettings();
        loadUserId();
        loadUserFolder();
        loadBackupFolder();
        loadUserSettings();

        ComBean bean = new ComBean();
        bean.setApplicationName(Constants.TITLE);
        bean.setArguments(args);

        CommunicatorUtils.send(bean, "127.0.0.1", SETTINGS.getIntegerProperty("general.communicator.port"));
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

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

public static Application getApplication() {
    Application app = null;/*from  w w  w.java2  s  . c o  m*/
    try {
        app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication")
                .invoke(null);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return app;
}

From source file:net.sourceforge.docfetcher.util.AppUtil.java

@SuppressAjWarnings
private static void showStackTrace(final Display display, final Throwable throwable) {
    // Print stacktrace to System.err
    throwable.printStackTrace();

    // Prepend useful program info to the stacktrace
    StringBuilder sb = new StringBuilder();
    sb.append("program.name=" + Const.PROGRAM_NAME.value + Util.LS);
    sb.append("program.version=" + Const.PROGRAM_VERSION.value + Util.LS);
    sb.append("program.build=" + Const.PROGRAM_BUILD_DATE.value + Util.LS);
    sb.append("program.portable=" + Const.IS_PORTABLE.asBoolean() + Util.LS);
    String[] keys = { "java.runtime.name", "java.runtime.version", "java.version", "sun.arch.data.model",
            "os.arch", "os.name", "os.version", "user.language" };
    for (String key : keys)
        sb.append(key + "=" + System.getProperty(key) + Util.LS);

    // Get stacktrace as string
    StringWriter writer = new StringWriter();
    throwable.printStackTrace(new PrintWriter(writer));
    sb.append(writer.toString());/*  www.  j  a  v a 2 s  .  c  o m*/
    final String trace = sb.toString();

    // Write stacktrace to file
    String timestamp = new SimpleDateFormat("yyyyMMdd-HHmm").format(new Date());
    String traceFilename = "stacktrace_" + timestamp + ".txt";
    final File traceFile = new File(getAppDataDir(), traceFilename);
    try {
        Files.write(trace, traceFile, Charsets.UTF_8);
    } catch (IOException e) {
        e.printStackTrace(); // We'll give up here
    }

    // Show stacktrace in error window
    Util.runSwtSafe(display, new Runnable() {
        public void run() {
            StackTraceWindow window = new StackTraceWindow(display);
            window.setTitle(throwable.getClass().getSimpleName());
            String path = Util.getSystemAbsPath(traceFile);
            String link = String.format("<a href=\"%s\">%s</a>", path, path);
            String msg = Messages.program_died_stacktrace_written.format(link);
            window.setText(msg);
            Image icon = display.getSystemImage(SWT.ICON_WARNING);
            window.setTitleImage(icon);

            /*
             * It appears that when you paste a stracktrace with Windows
             * newlines into the text field of a SourceForge.net bug report,
             * the newlines will end up being duplicated. The workaround is
             * to use Linux newlines in the stacktrace window.
             */
            window.setStackTrace(Util.ensureLinuxLineSep(trace));

            window.open();
        }
    });
}

From source file:com.samczsun.helios.Helios.java

private static boolean ensurePython3Set0(boolean forceCheck) {
    String python3Location = Settings.PYTHON3_LOCATION.get().asString();
    if (python3Location.isEmpty()) {
        SWTUtil.showMessage("You need to set the location of the Python/PyPy 3.x executable", true);
        setLocationOf(Settings.PYTHON3_LOCATION);
        python3Location = Settings.PYTHON3_LOCATION.get().asString();
    }//from  ww  w .  ja va  2s.c  om
    if (python3Location.isEmpty()) {
        return false;
    }
    if (python3Verified == null || forceCheck) {
        try {
            Process process = new ProcessBuilder(python3Location, "-V").start();
            String result = IOUtils.toString(process.getInputStream());
            String error = IOUtils.toString(process.getErrorStream());
            python3Verified = error.startsWith("Python 3") || result.startsWith("Python 3");
        } catch (Throwable t) {
            t.printStackTrace();
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            SWTUtil.showMessage("The Python 3.x executable is invalid." + Constants.NEWLINE + Constants.NEWLINE
                    + sw.toString());
            python3Verified = false;
        }
    }
    return python3Verified;
}