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.heliosdecompiler.helios.bootloader.Bootloader.java

private static void displayError(Throwable t) {
    t.printStackTrace();
    StringWriter writer = new StringWriter();
    t.printStackTrace(new PrintWriter(writer));
    JOptionPane.showMessageDialog(null, writer.toString(), t.getClass().getSimpleName(),
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:dk.netarkivet.common.utils.ApplicationUtils.java

/**
 * Helper class for logging an exception (at level fatal)
 * and printing it to STDOUT at the same time.
 * Also invokes the error notifier.//from   www  .j a v  a2 s.co  m
 * @param s a given String.
 * @param t a given Exception.
 */
private static void logExceptionAndPrint(String s, Throwable t) {
    System.out.println(s);
    t.printStackTrace();
    log.fatal(s, t);
    NotificationsFactory.getInstance().notify(s, NotificationType.ERROR, t);
}

From source file:Main.java

/** Writes a copy of a file.
 * /*from   www  . j  av  a2  s  .com*/
 * @param src the file to copy
 * @param dst the location to write the new file
 * @throws IOException
 */
public synchronized static void copy(File src, File dst) throws IOException {
    if (b1 == null)
        b1 = new byte[4096];

    FileInputStream in = null;
    FileOutputStream out = null;
    try {
        in = new FileInputStream(src);
        dst.getParentFile().mkdirs();
        dst.createNewFile();
        out = new FileOutputStream(dst);
        int k = in.read(b1);
        while (k != -1) {
            out.write(b1, 0, k);
            k = in.read(b1);
        }
    } finally {
        try {
            in.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
        try {
            out.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

From source file:net.creativeparkour.CreativeParkour.java

/**
 * Envoie l'erreur au site si c'est autoris, l'affiche dans la console sinon
 * @param code Code de l'erreur/*from   w ww .j  a  v a  2 s.c  o m*/
 * @param e Exception
 * @param envoyer Si true, on tente de l'envoyer au site, sinon on l'affiche juste
 */
static void erreur(String code, Throwable e, boolean envoyer) {
    e.printStackTrace();
    return;

    /*String err = exceptionToString(e);
    Bukkit.getLogger().warning(Config.prefix(false) + "An error occurred, sending it to " + lienSiteCourt() + "...\nError: " + err);
            
    if (Config.getConfig().getBoolean("enable data collection") && envoyer)
    {
       HashMap<String, String> params = new HashMap<String, String>();
       params.put("versionServeur", Bukkit.getServer().getVersion());
       params.put("onlineMode", String.valueOf(Bukkit.getOnlineMode()));
       params.put("erreur", "[E:" + code + "] " + err);
       try {
    CPRequest.effectuerRequete("erreurs.php", params, null, null, null);
       } catch (SecurityException e1) {
    erreur("0", e, false);
       }
    }
    else
    {
       Bukkit.getLogger().warning(Config.prefix(false) + "The last error (error " + code + ") can not be reported, please send it to obelus@creativeparkour.net");
    }*/
}

From source file:com.google.dart.tools.designer.model.HtmlRenderHelper.java

/**
 * @return the image of given HTML content, may be <code>null</code>.
 *//*from w ww.jav a 2s  .c om*/
public static Image renderImage(final String content) {
    try {
        File tempFile = File.createTempFile("htmlRender", ".html");
        try {
            IOUtils2.writeBytes(tempFile, content.getBytes());
            // start DumpRenderTree
            if (processOutputStream == null) {
                String path;
                {
                    Bundle bundle = DartDesignerPlugin.getDefault().getBundle();
                    URL url = bundle.getEntry("lib/DumpRenderTree.app/Contents/MacOS/DumpRenderTree");
                    path = FileLocator.toFileURL(url).getPath();
                }
                //        ProcessBuilder builder = new ProcessBuilder(path, "-p", tempFile.getAbsolutePath());
                ProcessBuilder builder = new ProcessBuilder(path, "-p", "-");
                builder.redirectErrorStream(true);
                Process process = builder.start();
                processOutputStream = process.getOutputStream();
                processInputStream = process.getInputStream();
                processReader = new BufferedReader(new InputStreamReader(processInputStream));
            }
            long start = System.nanoTime();
            // XXX
            //        processOutputStream.write((tempFile.getAbsolutePath() + "\n").getBytes());
            processOutputStream
                    .write(("http://127.0.0.1:3030/Users/scheglov/dart/dwc_first/web/out/dwc_first.html\n")
                            .getBytes());
            processOutputStream.flush();
            // read tree
            while (true) {
                String line = processReader.readLine();
                System.out.println(line);
                if (line.isEmpty()) {
                    break;
                }
            }
            // read image
            {
                processReader.readLine(); // ActualHash:
                processReader.readLine(); // Content-Type: image/png
                String lengthLine = processReader.readLine(); // Content-Length: 5546
                int pngLength = Integer.parseInt(StringUtils.removeStart(lengthLine, "Content-Length: "));
                //          System.out.println("pngLength: " + pngLength);
                char[] pngChars = new char[pngLength];
                readFully(processReader, pngChars);
                byte[] pngBytes = new String(pngChars).getBytes();
                Image image = new Image(null, new ByteArrayInputStream(pngBytes));
                System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0);
                return image;
            }
            //
            //        {
            //          SessionInputBuffer buffer = new AbstractSessionInputBuffer() {
            //            {
            //              init(processInputStream, 1024, new BasicHttpParams());
            //            }
            //
            //            @Override
            //            public boolean isDataAvailable(int timeout) throws IOException {
            //              return false;
            //            }
            //          };
            //          LineParser lineParser = new BasicLineParser(new ProtocolVersion("HTTP", 1, 1));
            //          HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
            //              buffer,
            //              lineParser,
            //              new DefaultHttpResponseFactory(),
            //              new BasicHttpParams());
            //          HttpResponse response = parser.parse();
            //          System.out.println(response);
            //          HttpParams params = new BasicHttpParams();
            //          SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
            //          HttpMessageParser<BasicHttpResponse> parser = new DefaultResponseParser(
            //              inbuffer,
            //              BasicLineParser.DEFAULT,
            //              new DefaultHttpResponseFactory(),
            //              params);
            //
            //          HttpResponse response = parser.parse();
            //        }
            //        while (true) {
            //          String line = processReader.readLine();
            //          System.out.println(line);
            //        }
            //
            //        byte[] bytes = IOUtils2.readBytes(processInputStream);
            //        int exitValue = process.exitValue();
            //        System.out.println("bytes: " + bytes.length);
            //        System.out.println("bytesTime: " + (System.nanoTime() - start) / 1000000.0);
            //        String output = new String(bytes);
            //        System.out.println(StringUtils.substring(output, -10, 0));
            ////        System.out.println(output);
            //        //
            //        int pngOffset = output.indexOf("Content-Type: image/png");
            //        pngOffset = output.indexOf('\n', pngOffset) + 1;
            //        pngOffset = output.indexOf('\n', pngOffset) + 1;
            //        Image image = new Image(null, new ByteArrayInputStream(bytes, pngOffset, bytes.length
            //            - pngOffset));
            //        System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0);
            //        return image;
        } finally {
            tempFile.delete();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

public static ImgBuffer draw(int width, int height, CPUAlgebraicSurfaceRenderer.AntiAliasingMode aam,
        AntiAliasingPattern aap) {/*from  w  w w  .  j a  v a 2 s .com*/
    // create color buffer
    ImgBuffer ib = new ImgBuffer(width, height);

    // do rendering
    Matrix4d transform = new Matrix4d();
    transform.mul(basic_rotation, additional_rotation);
    asr.setTransform(transform);
    asr.setSurfaceTransform(scale);
    asr.setAntiAliasingMode(aam);
    asr.setAntiAliasingPattern(aap);
    setOptimalCameraDistance(asr.getCamera());

    try {
        asr.draw(ib.rgbBuffer, width, height);
        return ib;
    } catch (RenderingInterruptedException rie) {
        return null;
    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}

From source file:com.espertech.esper.support.util.SupportMessageAssertUtil.java

public static void assertMessageContains(Throwable ex, String message) {
    if (!ex.getMessage().contains(message)) {
        Assert.fail("Does not contain text: '" + message + "' in text \n text:" + ex.getMessage());
    }/*from   ww w.j  av  a 2 s.  c  om*/
    if (message.trim().length() == 0) {
        ex.printStackTrace();
        Assert.fail("empty expected message");
    }
}

From source file:com.xlson.standalonewar.Starter.java

/**
 * Add url to the system class loader./*from www.  j  a  va2 s. c o m*/
 */
public static void appendClasspath(URL url) throws IOException {

    URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Class sysclass = URLClassLoader.class;

    try {
        Method method = sysclass.getDeclaredMethod("addURL", parameters);
        method.setAccessible(true);
        method.invoke(sysloader, new Object[] { url });
    } catch (Throwable t) {
        t.printStackTrace();
        throw new IOException("Error, could not add URL to system classloader");
    }

}

From source file:org.apache.jena.fuseki.embedded.FusekiTestServer.java

static void resetServer() {
    if (countServer.get() == 0)
        throw new RuntimeException("No server started!");
    if (CLEAR_DSG_DIRECTLY) {
        Txn.executeWrite(dsgTesting, () -> dsgTesting.clear());
    } else {/*  ww w.  ja v a2  s . c  o m*/
        Update clearRequest = new UpdateDrop(Target.ALL);
        UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, serviceUpdate());
        try {
            proc.execute();
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
    }
}

From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java

private static Object run(Object o, GroovyShell shell, Binding binding) {
    try {//from www  .j a  va 2 s . co  m
        Script script = null;
        String var = null;
        if (o instanceof File) {
            File f = (File) o;
            var = f.getName().replaceAll("\\.groovy$", "");
            script = shell.parse(f);
        } else if (o instanceof String) {
            script = shell.parse((String) o);
        }
        if (null != script && null != var) {
            binding.setVariable(var, script);
        }
        return script.run();
    } catch (Throwable t) {
        // Doesn't do much good to dispatch into a script that has a syntax error, so...
        t.printStackTrace();
    }
    return null;
}