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:Main.java

public static void logThrowable(Throwable e) {
    if (DEBUG) {//from  w ww . j  a v a  2 s  . c o  m
        Log.e("LogUtil", e.toString());
        e.printStackTrace();
        if (LOG_TO_FILE) {
            logToFile(e);
        }
    }
}

From source file:info.devopsabyss.CallSeleniumTest.java

private static void printStackTraceWhenVerbose(final CommandLine cmd, final Throwable ex) {
    if (cmd.hasOption("v")) {
        ex.printStackTrace();
    }/* w ww  .ja v  a2 s.  c  o  m*/
}

From source file:com.chiorichan.maven.MavenUtils.java

public static boolean loadLibrary(MavenLibrary lib) {
    String urlJar = MavenUtils.resolveMavenUrl(lib.group, lib.name, lib.version, "jar");
    String urlPom = MavenUtils.resolveMavenUrl(lib.group, lib.name, lib.version, "pom");
    File mavenBaseFile = new File(LIBRARY_DIR, lib.group.replaceAll("\\.", "/") + "/" + lib.name + "/"
            + lib.version + "/" + lib.name + "-" + lib.version);
    File mavenLocalJarFile = new File(mavenBaseFile + ".jar");
    File mavenLocalPomFile = new File(mavenBaseFile + ".pom");

    if (urlJar == null || urlJar.isEmpty() || urlPom == null || urlPom.isEmpty())
        return false;

    try {/*from   ww  w .  j  a  va  2s. c  o m*/
        if (!mavenLocalPomFile.exists() || !mavenLocalJarFile.exists()) {
            PluginManager.getLogger().info(ConsoleColor.GOLD + "Downloading the library `" + lib.toString()
                    + "` from url `" + urlJar + "`... Please Wait!");

            if (!downloadFile(urlPom, mavenLocalPomFile))
                return false;

            if (!downloadFile(urlJar, mavenLocalJarFile))
                return false;
        }

        PluginManager.getLogger().info(ConsoleColor.GOLD + "Loading the library `" + lib.toString()
                + "` from file `" + mavenLocalJarFile + "`...");

        MavenClassLoader.addFile(mavenLocalJarFile);
    } catch (Throwable t) {
        t.printStackTrace();
        return false;
    }

    loadedLibraries.add(lib.group + ":" + lib.name);

    return true;
}

From source file:EventDispatcher.java

public static void fireEvent(final Dispatcher dispatcher, final List listeners, final Object evt,
        final boolean useEventQueue) {
    if (useEventQueue && !EventQueue.isDispatchThread()) {
        Runnable r = new Runnable() {
            public void run() {
                fireEvent(dispatcher, listeners, evt, useEventQueue);
            }/*from  www.  jav a2  s  .  c  o  m*/
        };
        try {
            EventQueue.invokeAndWait(r);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            // Assume they will get delivered????
            // be nice to wait on List but how???
        } catch (ThreadDeath td) {
            throw td;
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return;
    }

    Object[] ll = null;
    Throwable err = null;
    int retryCount = 10;
    while (--retryCount != 0) {
        // If the thread has been interrupted this can 'mess up'
        // the class loader and cause this otherwise safe code to
        // throw errors.
        try {
            synchronized (listeners) {
                if (listeners.size() == 0)
                    return;
                ll = listeners.toArray();
                break;
            }
        } catch (Throwable t) {
            err = t;
        }
    }
    if (ll == null) {
        if (err != null)
            err.printStackTrace();
        return;
    }
    dispatchEvent(dispatcher, ll, evt);
}

From source file:com.mirth.connect.model.converters.DICOMConverter.java

public static byte[] dicomObjectToByteArray(DicomObject dicomObject) throws IOException {
    BasicDicomObject basicDicomObject = (BasicDicomObject) dicomObject;
    DicomOutputStream dos = null;//ww  w. jav a 2s  .  co m

    try {
        ByteCounterOutputStream bcos = new ByteCounterOutputStream();
        ByteArrayOutputStream baos;

        if (basicDicomObject.fileMetaInfo().isEmpty()) {
            try {
                // Create a dicom output stream with the byte counter output stream.
                dos = new DicomOutputStream(bcos);
                // "Write" the dataset once to determine the total number of bytes required. This is fast because no data is actually being copied.
                dos.writeDataset(basicDicomObject, TransferSyntax.ImplicitVRLittleEndian);
            } finally {
                IOUtils.closeQuietly(dos);
            }

            // Create the actual byte array output stream with a buffer size equal to the number of bytes required.
            baos = new ByteArrayOutputStream(bcos.size());
            // Create a dicom output stream with the byte array output stream
            dos = new DicomOutputStream(baos);

            // Create ACR/NEMA Dump
            dos.writeDataset(basicDicomObject, TransferSyntax.ImplicitVRLittleEndian);
        } else {
            try {
                // Create a dicom output stream with the byte counter output stream.
                dos = new DicomOutputStream(bcos);
                // "Write" the dataset once to determine the total number of bytes required. This is fast because no data is actually being copied.
                dos.writeDicomFile(basicDicomObject);
            } finally {
                IOUtils.closeQuietly(dos);
            }

            // Create the actual byte array output stream with a buffer size equal to the number of bytes required.
            baos = new ByteArrayOutputStream(bcos.size());
            // Create a dicom output stream with the byte array output stream
            dos = new DicomOutputStream(baos);

            // Create DICOM File
            dos.writeDicomFile(basicDicomObject);
        }

        // Memory Optimization since the dicom object is no longer needed at this point.
        dicomObject.clear();

        return baos.toByteArray();
    } catch (IOException e) {
        throw e;
    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    } finally {
        IOUtils.closeQuietly(dos);
    }
}

From source file:fi.iki.dezgeg.matkakorttiwidget.gui.MatkakorttiWidgetApp.java

public static AsyncTask<Void, Void, Void> reportException(final String where, final Throwable e) {
    e.printStackTrace();
    if (prefs.getLong("lastErrorReport", new Date().getTime()) - new Date().getTime() <= MIN_REPORT_INTERVAL_MS)
        return null;
    prefs.edit().putLong("lastErrorReport", new Date().getTime()).commit();

    return new AsyncTask<Void, Void, Void>() {

        @Override// w  w w. j a v a  2  s . c  o  m
        protected Void doInBackground(Void... voids) {
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                List<NameValuePair> data = new ArrayList<NameValuePair>();
                data.add(new BasicNameValuePair("where", where));
                data.add(new BasicNameValuePair("backtrace", sw.toString()));
                if (packageInfo != null) {
                    data.add(new BasicNameValuePair("version", String.format("%s (%s %s)",
                            packageInfo.versionName, packageInfo.versionCode, DEBUG ? "debug" : "release")));
                }

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost post = new HttpPost(ERROR_REPORT_URL);
                try {
                    post.setEntity(new UrlEncodedFormEntity(data));
                } catch (UnsupportedEncodingException uee) {
                }
                try {
                    httpclient.execute(post);
                    System.out.println("Error reported.");
                } catch (IOException e1) {
                }
            } catch (Throwable t) {
                // ignore
            }
            return null;
        }
    }.execute();
}

From source file:com.machinepublishers.jbrowserdriver.diagnostics.HttpServer.java

private static byte[][] resource(String path, String status, String contentType) {
    byte[] bodyTmp = null;
    byte[] contentTmp = null;
    try (InputStream inputStream = HttpServer.class.getResourceAsStream(path)) {
        bodyTmp = IOUtils.toByteArray(inputStream);
        contentTmp = new String("HTTP/1.1 " + status + "\n" + "Content-Length: " + bodyTmp.length + "\n"
        //Don't set content-type for text/html -- test that it's added automatically
                + (contentType == null ? "" : "Content-Type: " + contentType + "\n")
                + "Expires: Sun, 09 Feb 2116 01:01:01 GMT\n" + "Connection: close\n\n").getBytes("utf-8");
    } catch (Throwable t) {
        t.printStackTrace();
    }/*  w w w . j a  v  a  2s. co m*/
    return new byte[][] { bodyTmp, contentTmp };
}

From source file:Main.java

public static void writeXMLDocToFile(Document outputDoc, String outFileName) {
    try {/*w  w  w.j  a v a  2  s. c o m*/
        //FileWriter writer = new FileWriter( outFileName );
        final String encoding = "UTF-8";
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outFileName), encoding);
        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();

        DOMSource source = new DOMSource(outputDoc);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Could not create output XML file: " + outFileName);
    } catch (TransformerConfigurationException tce) {
        // Error generated by the parser
        System.out.println("* Transformer Factory error");
        System.out.println("  " + tce.getMessage());

        // Use the contained exception, if any
        Throwable x = tce;
        if (tce.getException() != null)
            x = tce.getException();
        x.printStackTrace();
    } catch (TransformerException te) {
        // Error generated by the parser
        System.out.println("* Transformation error");
        System.out.println("  " + te.getMessage());

        // Use the contained exception, if any
        Throwable x = te;
        if (te.getException() != null)
            x = te.getException();
        x.printStackTrace();
    }
}

From source file:controllers.Facets.java

private static Promise<org.elasticsearch.search.facet.Facets> getElasticsearchFacets(String id, String q,
        String author, String name, String subject, String publisher, String issued, String medium,
        String owner, String set, String nwbibspatial, String nwbibsubject, String field, int size, String t,
        String location) {//  w  w  w.  j  a  v  a  2 s . c o  m
    Promise<org.elasticsearch.search.facet.Facets> promise = Promise.promise(() -> {
        QueryBuilder query = createQuery(id, q, author, name, subject, publisher, issued, medium, set,
                nwbibspatial, nwbibsubject, owner, t, location);
        SearchRequestBuilder req = createRequest(owner, field, query, size);
        long start = System.currentTimeMillis();
        SearchResponse res = req.execute().actionGet();
        Logger.debug("Got facets for q={}, owner={}, field={}; took {} ms.", q, owner, field,
                (System.currentTimeMillis() - start));
        return res.getFacets();
    }).recover((Throwable x) -> {
        x.printStackTrace();
        return null;
    });
    return promise;
}

From source file:com.hula.lang.util.DotNotationUtil.java

public static void setProperty(String name, Object source, Object value, int index) {
    // last item in the path is the target property name
    //// ww w.  j av a2s .c  o m
    // i.e. script.description
    //
    // we're looking up to script, then to description
    String targetProperty = getLastItem(name);

    String[] path = getPath(name);

    // refine the source down to the correct object
    for (int i = index; index != path.length - 1; index++) {
        String item = path[i];

        source = reflect(source, item);

    }

    // now do the set
    try {
        PropertyUtils.setProperty(source, targetProperty, value);
    } catch (Throwable t) {
        t.printStackTrace();
    }

}