Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:au.edu.anu.portal.portlets.sakaiconnector.utils.XmlParser.java

/**
 * Check if the given XML validates to the given class type
 * @param serializer/*from www .j a v  a 2 s  .  c o  m*/
 * @param clazz
 * @param xml
 * @return
 * @throws Exception 
 */
private static boolean isValid(Serializer serializer, Class<?> clazz, String xml) {

    if (StringUtils.isBlank(xml)) {
        return false;
    }

    try {
        if (serializer.validate(clazz, xml)) {
            return true;
        }
    } catch (Exception e) {
        log.error("Unable to validate xml: " + e.getClass().getName() + ": " + e.getMessage());
    }
    return false;
}

From source file:msi.gama.util.file.GamaFileMetaData.java

public static <T extends IGamaFileMetaData> T from(final String s, final long stamp, final Class<T> clazz,
        final boolean includeOutdated) {
    T result = null;//from  w w w  . j  a v a2 s  .c  o m
    try {
        final Constructor<T> c = clazz.getDeclaredConstructor(String.class);
        result = c.newInstance(s);
        final boolean hasFailed = result.hasFailed();
        if (!hasFailed && !includeOutdated && result.getModificationStamp() != stamp) {
            return null;
        }
    } catch (final Exception ignore) {
        DEBUG.ERR("Error loading metadata " + s + " : " + ignore.getClass().getSimpleName() + ":"
                + ignore.getMessage());
        if (ignore instanceof InvocationTargetException && ignore.getCause() != null) {
            ignore.getCause().printStackTrace();
        }
    }
    return result;
}

From source file:com.batontouch.facebook.SessionStore.java

private static void authenticate(String token) throws ClientProtocolException, IOException {
    FacebookServerLogin(token);//from www .  j  a  v a  2 s . c o m
    try {

    } catch (Exception e) {
        Log.e("my", e.getClass().getName() + e.getMessage() + "LoginError");
    }
}

From source file:com.homesnap.webserver.utils.JSonTools.java

private final static String formatException(Exception e) {
    return "{" + ERROR + ": [{" + ERROR_CLASSNAME + ":'" + JSONObject.quote(e.getClass().getSimpleName())
            + "', " + ERROR_MESSAGE + " :'" + JSONObject.quote(e.getMessage()) + "'}]}";
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.property.CloneablePropertyCloner.java

private static Cloneable clone(Cloneable cloneable) throws IllegalArgumentException {
    /*/*  w ww .  j  a  v a  2  s .c o m*/
     * Assumes - in spite of the detailed warnings in the documentation
     * for Clonable - that the cloneable *will* have a public clone() method,
     * as per convention.
     */
    try {
        return (Cloneable) cloneable.getClass().getMethod("clone", (Class[]) null).invoke(cloneable,
                (Object[]) null);
    } catch (Exception exception) {
        throw new IllegalArgumentException("Unable to clone " + cloneable + " due to "
                + exception.getClass().getSimpleName() + ": " + exception.getMessage());
    }

}

From source file:com.netscape.cmstools.OCSPClient.java

public static void printError(Exception e) {
    String message = e.getClass().getSimpleName();
    if (e.getMessage() != null) {
        message += ": " + e.getMessage();
    }/*from  w w w. j  a v a  2 s  .  c o m*/
    printError(message);
}

From source file:baggage.BaseTestCase.java

protected static void assertFailure(Class<? extends Exception> klass, Fallible fallible) {
    try {/*  w w  w  .j ava  2s . c  o m*/
        fallible.execute();
    } catch (Exception e) {
        if (!klass.isAssignableFrom(e.getClass())) {
            throw new RuntimeException(
                    "Expected a " + klass.getSimpleName() + ", got a " + e.getClass().getSimpleName(), e);
        }
        return;
    }
    Assert.fail("Expected a " + klass.getSimpleName() + ", got no exceptions at all");
}

From source file:org.jwebsocket.sso.HTTPSupport.java

/**
 *
 * @param aURL//w  w  w .j  av a2s . com
 * @param aMethod
 * @param aHeaders
 * @param aPostBody
 * @param aTimeout
 * @return
 */
public static String request(String aURL, String aMethod, Map<String, String> aHeaders, String aPostBody,
        long aTimeout) {
    if (mLog.isDebugEnabled()) {
        mLog.debug("Requesting (" + aMethod + ") '" + aURL + "', timeout: " + aTimeout + "ms, Headers: "
                + aHeaders + ", Body: "
                + (null != aPostBody ? "'" + aPostBody.replace("\n", "\\n").replace("\r", "\\r") + "'"
                        : "[null]"));
    }
    String lResponse = "{\"code\": -1, \"msg\": \"undefined\"";
    try {
        KeyStore lTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        lTrustStore.load(null, null);
        // Trust own CA and all self-signed certs
        SSLContext lSSLContext = SSLContexts.custom()
                .loadTrustMaterial(lTrustStore, new TrustSelfSignedStrategy()).build();
        // Allow TLSv1 protocol only
        SSLConnectionSocketFactory lSSLFactory = new SSLConnectionSocketFactory(lSSLContext,
                new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        CloseableHttpClient lHTTPClient = HttpClients.custom().setSSLSocketFactory(lSSLFactory).build();
        HttpUriRequest lRequest;
        if ("POST".equals(aMethod)) {
            lRequest = new HttpPost(aURL);
            ((HttpPost) lRequest).setEntity(new ByteArrayEntity(aPostBody.getBytes("UTF-8")));
        } else {
            lRequest = new HttpGet(aURL);
        }
        for (Map.Entry<String, String> lEntry : aHeaders.entrySet()) {
            lRequest.setHeader(lEntry.getKey(), lEntry.getValue());
        }

        // System.out.println("Executing request " + lRequest.getRequestLine());
        // Create a custom response handler
        ResponseHandler<String> lResponseHandler = new ResponseHandler<String>() {

            @Override
            public String handleResponse(final HttpResponse lResponse)
                    throws ClientProtocolException, IOException {
                int lStatus = lResponse.getStatusLine().getStatusCode();
                HttpEntity lEntity = lResponse.getEntity();
                return lEntity != null ? EntityUtils.toString(lEntity) : null;

                //               if (lStatus >= 200 && lStatus < 300) {
                //                  HttpEntity entity = lResponse.getEntity();
                //                  return entity != null ? EntityUtils.toString(entity) : null;
                //               } else {
                //                  throw new ClientProtocolException("Unexpected response status: " + lStatus);
                //               }
            }

        };
        long lStartedAt = System.currentTimeMillis();
        lResponse = lHTTPClient.execute(lRequest, lResponseHandler);
        if (mLog.isDebugEnabled()) {
            mLog.debug("Response (" + (System.currentTimeMillis() - lStartedAt) + "ms): '"
                    + lResponse.replace("\n", "\\n").replace("\r", "\\r") + "'");
        }
        return lResponse;
    } catch (Exception lEx) {
        String lMsg = "{\"code\": -1, \"msg\": \"" + lEx.getClass().getSimpleName() + " at http request: "
                + lEx.getMessage() + "\"}";
        mLog.error(lEx.getClass().getSimpleName() + ": " + lEx.getMessage() + ", returning: " + lMsg);
        lResponse = lMsg;
        return lResponse;
    }
}

From source file:com.discovery.darchrow.bean.PropertyUtil.java

/**
 * <code>bean</code>???/Map.
 * /* w w  w.j  a  va  2  s  .  c  o  m*/
 * <p>
 * ???classObject??classjava.lang.Object
 * </p>
 *
 * @param bean
 *            Bean whose properties are to be extracted
 * @return The set of properties for the bean
 * @see org.apache.commons.beanutils.BeanUtils#describe(Object)
 * @see org.apache.commons.beanutils.PropertyUtils#describe(Object)
 * @see com.baozun.nebulaplus.bean.BeanUtil#describe(Object)
 */
public static Map<String, Object> describe(Object bean) {
    try {
        //Return the entire set of properties for which the specified bean provides a read method.
        Map<String, Object> propertyMap = PropertyUtils.describe(bean);
        return propertyMap;
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:edu.byu.nlp.util.asserts.MoreAsserts.java

public static void assertFails(Runnable runnable, Class<? extends Exception> expectedException) {
    try {/* ww w  .  j  a  v a2  s  .co  m*/
        runnable.run();
    } catch (Exception e) {

        if (!expectedException.isInstance(e)) {
            Fail.fail("Threw the wrong kind of exception: " + e.getClass().getName()
                    + " instead of the expected " + expectedException.getName(), e);
        }

        return; // good failure
    }

    Fail.fail("should have thrown a " + expectedException.getName() + " exception but did not!");

}