Example usage for java.lang Error Error

List of usage examples for java.lang Error Error

Introduction

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

Prototype

public Error(String message, Throwable cause) 

Source Link

Document

Constructs a new error with the specified detail message and cause.

Usage

From source file:com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon.java

private ScalableIcon(final String name) {
    final InputStream in = ScalableIcon.class.getClassLoader()
            .getResourceAsStream("com/igormaznitsa/mindmap/swing/panel/icons/" + name); //NOI18N
    try {/*from   w  w  w  . j a v a  2s . c  o m*/
        this.baseImage = ImageIO.read(in);
        this.scaledCachedImage = null;
        this.baseScaleX = (float) BASE_WIDTH / (float) this.baseImage.getWidth(null);
        this.baseScaleY = (float) BASE_HEIGHT / (float) this.baseImage.getHeight(null);
    } catch (Exception ex) {
        throw new Error("Can't load resource image " + name, ex); //NOI18N
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.mattbertolini.statusboard.view.graph.Graph.java

public static Graph error(final String message, final String detailMessage) {
    Error error = new Error(message, detailMessage);
    Graph graph = new Graph();
    graph.setError(error);/*w w  w  .  ja v  a 2 s . c  o m*/
    return graph;
}

From source file:com.manydesigns.portofino.pageactions.PageActionLogic.java

public static String getScriptTemplate(Class<?> actionClass) {
    if (!PageAction.class.isAssignableFrom(actionClass)) {
        return null;
    }/*from  ww  w . j  a va  2 s. c om*/
    ScriptTemplate scriptTemplate = actionClass.getAnnotation(ScriptTemplate.class);
    if (scriptTemplate != null) {
        String templateLocation = scriptTemplate.value();
        try {
            return IOUtils.toString(actionClass.getResourceAsStream(templateLocation));
        } catch (Exception e) {
            throw new Error(
                    "Can't load script template: " + templateLocation + " for class: " + actionClass.getName(),
                    e);
        }
    } else {
        String template = getScriptTemplate(actionClass.getSuperclass());
        if (template != null) {
            return template;
        } else {
            try {
                InputStream stream = PageActionLogic.class.getResourceAsStream(
                        "/com/manydesigns/portofino/pageactions/default_script_template.txt");
                return IOUtils.toString(stream);
            } catch (Exception e) {
                throw new Error("Can't load script template", e);
            }
        }
    }
}

From source file:info.magnolia.cms.util.ExceptionUtil.java

/**
 * This method helps palliating the absence of multi-catch (introduced in Java 7) - catch the lower common
 * denominator exception and let this method do the rest - <strong>Use with great care!</strong>.
 * <strong>Warning:</strong> this method can be abused, and would let one throw undeclared exceptions, which would
 * in turn produce unexpected and undesirable effects on calling code. Just resist the urge to use this outside
 * "multi-catch" scenarios.// www  .j av  a2s .c o  m
 */
@SuppressWarnings("unchecked")
public static void rethrow(Throwable e, Class<? extends Throwable>... allowedExceptions) {
    if (RuntimeException.class.isInstance(e)) {
        throw (RuntimeException) e;
    }
    for (Class<? extends Throwable> allowedException : allowedExceptions) {
        if (allowedException.isInstance(e)) {
            sneakyThrow(e);
        }
    }
    throw new Error("Caught the following exception, which was not allowed: ", e);
}

From source file:com.igormaznitsa.mindmap.swing.services.DefaultImageIconService.java

@Nonnull
private static Icon loadIcon(@Nonnull final String name) {
    final InputStream in = ScalableIcon.class.getClassLoader()
            .getResourceAsStream("com/igormaznitsa/mindmap/swing/panel/icons/" + name); //NOI18N
    try {/* ww  w . j av  a2s  .c om*/
        return new ImageIcon(ImageIO.read(in));
    } catch (IOException ex) {
        throw new Error("Can't load icon " + name, ex); //NOI18N
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.eviware.soapui.impl.support.HttpUtils.java

public static String urlEncodeWithUtf8(String input) {
    try {/*from   www  .ja  va  2s .c om*/
        return URLEncoder.encode(input, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // if UTF-8 isn't available we might as well die ...
        throw new Error("Unexpected error: charset UTF-8 not available", e);
    }
}

From source file:org.thiesen.hafas.Client.java

public Response doRequest(final Request request) throws ClientException {
    final HttpPost postMethod = new HttpPost(_config.getBaseUrl());

    try {/*w w w .  j  a va2s. com*/
        final String requestString = request.makeStringRepresentation(_config);

        System.out.println(requestString);
        postMethod.setEntity(new StringEntity(requestString, _config.getEncoding().name()));
    } catch (final UnsupportedEncodingException e) {
        throw new Error("Invalid java, UTF-8 not supported", e);
    }

    try {
        final HttpResponse httpResponse = _httpClient.execute(postMethod);

        final StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine.getStatusCode() != 200) {
            handleErrorResponse(httpResponse, statusLine);
        } else {
            final String extractedResponseContent = extractResponseContent(httpResponse);

            return request.makeResponseFrom(extractedResponseContent);
        }

    } catch (final RuntimeException e) {
        postMethod.abort();
        throw new ClientException(e);
    } catch (final ClientProtocolException e) {
        throw new ClientException(e);
    } catch (final IOException e) {
        throw new ClientException(e);
    }

    throw new RuntimeException("Should never arrive here!");

}

From source file:org.dspace.webmvc.controller.ResourceController.java

protected LookupResult lookupNoCache(HttpServletRequest req) {
    final String path = getPath(req);
    if (isForbidden(path)) {
        return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
    }/*from   ww  w . ja v a 2s. c  o  m*/

    final URL url;
    try {
        url = req.getSession().getServletContext().getResource(path);
    } catch (MalformedURLException e) {
        return new Error(HttpServletResponse.SC_BAD_REQUEST, "Malformed path");
    }

    final String mimeType = getMimeType(req, path);

    final String realpath = req.getSession().getServletContext().getRealPath(path);
    if (url != null && realpath != null) {
        // Try as an ordinary file
        File f = new File(realpath);
        if (!f.isFile()) {
            return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
        } else {
            return new StaticFile(f.lastModified(), mimeType, (int) f.length(), acceptsDeflate(req), url);
        }
    } else {
        ClassPathResource cpr = new ClassPathResource(path);
        if (cpr.exists()) {
            URL cprURL = null;
            try {
                cprURL = cpr.getURL();

                // Try as a JAR Entry
                final ZipEntry ze = ((JarURLConnection) cprURL.openConnection()).getJarEntry();
                if (ze != null) {
                    if (ze.isDirectory()) {
                        return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
                    } else {
                        return new StaticFile(ze.getTime(), mimeType, (int) ze.getSize(), acceptsDeflate(req),
                                cprURL);
                    }
                } else {
                    // Unexpected?
                    return new StaticFile(-1, mimeType, -1, acceptsDeflate(req), cprURL);
                }
            } catch (ClassCastException e) {
                // Unknown resource type
                if (url != null) {
                    return new StaticFile(-1, mimeType, -1, acceptsDeflate(req), cprURL);
                } else {
                    return new Error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error");
                }
            } catch (IOException e) {
                return new Error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error");
            }
        } else {
            return new Error(HttpServletResponse.SC_NOT_FOUND, "Not found");
        }
    }
}

From source file:org.apache.sling.testing.clients.util.FormEntityBuilder.java

public UrlEncodedFormEntity build() {
    try {/*from www  .jav a 2 s.  c  o  m*/
        return new UrlEncodedFormEntity(params, encoding);
    } catch (UnsupportedEncodingException ue) {
        throw new Error("Unexpected UnsupportedEncodingException", ue);
    }
}

From source file:edu.unc.lib.dl.util.FileUtils.java

/**
 * Creates a temporary copy of the original file or folder.
 *
 * @param file//from   w ww  .j  ava  2 s. c o  m
 *           the original file
 * @return the temporary file
 */
public static File tempCopy(File file) {
    try {
        File result = File.createTempFile("tempCopy", "");
        result.deleteOnExit();
        copyFolder(file, result);
        return result;
    } catch (IOException e) {
        throw new Error("Unexpected", e);
    }
}