Example usage for java.lang RuntimeException initCause

List of usage examples for java.lang RuntimeException initCause

Introduction

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

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:ome.util.ReflectionUtils.java

/**
 * call getter and return object./*  ww  w.j a v  a2s .c om*/
 * 
 * @DEV.TODO there maybe be cases where an exception is ok
 * @param target
 *            object on which to call getter
 * @param getter
 *            method for some field
 * @return value stored in field
 */
public static Object invokeGetter(Object target, Method getter) {
    RuntimeException re = new RuntimeException("Error trying to get value: " + getter.toString());
    Object result = null;
    try {
        result = getter.invoke(target, new Object[] {});
    } catch (IllegalArgumentException e) {
        re.initCause(e);
        throw re;
    } catch (IllegalAccessException e) {
        re.initCause(e);
        throw re;
    } catch (InvocationTargetException e) {
        re.initCause(e);
        throw re;
    }
    return result;
}

From source file:ome.util.ReflectionUtils.java

public static void setToNull(Object obj, Method setter) {
    RuntimeException re = new RuntimeException("Error trying to set to null: " + setter.toString());

    try {/*from   w w  w .j  a  va 2s  .co  m*/
        setter.invoke(obj, new Object[] { null });
    } catch (IllegalArgumentException e) {
        re.initCause(e);
        throw re;
    } catch (IllegalAccessException e) {
        re.initCause(e);
        throw re;
    } catch (InvocationTargetException e) {
        re.initCause(e);
        throw re;
    }
}

From source file:omero.cmd.SessionI.java

public void submit_async(AMD_Session_submit __cb, omero.cmd.Request req, Ice.Current current) {
    try {/*from w  w  w.ja va  2  s  . c  o m*/

        if (req == null || !IRequest.class.isAssignableFrom(req.getClass())) {
            log.info("Non-IRequest found:" + req);
            __cb.ice_response(null);
            return; // EARLY EXIT

        }

        Ice.Object servant = null;
        for (String key : Arrays.asList(req.ice_id(), _HandleTie.ice_staticId())) {
            try {
                servant = createServantDelegate(key);
                if (servant != null && servant instanceof IHandle) {
                    break;
                }
            } catch (Exception e) {
                log.debug(e.getClass().getName() + " on lookup of " + key);
            }
        }

        IHandle handle = null;
        if (servant != null) {
            if (servant instanceof Ice.TieBase) {
                Ice.TieBase tie = (Ice.TieBase) servant;
                Object delegate = tie.ice_delegate();
                if (IHandle.class.isAssignableFrom(delegate.getClass())) {
                    handle = (IHandle) delegate;
                }
            } else if (servant instanceof IHandle) {
                handle = (IHandle) servant;
            }
        }

        if (handle == null) {
            log.info("No handle found for " + req);
            InternalException ie = new InternalException();
            ie.message = "No handle found for " + req;
            __cb.ice_exception(ie);
            return; // EARLY EXIT
        }

        // ID
        Ice.Identity id = holder.getIdentity("IHandle" + UUID.randomUUID().toString());

        // Tie
        _HandleTie tie = (_HandleTie) servant;
        HandlePrx prx = HandlePrxHelper.checkedCast(registerServant(id, tie));

        // Init
        try {
            handle.initialize(id, (IRequest) req, current.ctx);
            executor.submit(current.ctx, Executors.callable(handle));
            __cb.ice_response(prx);
        } catch (Throwable e) {
            log.error("Exception on startup; removing handle " + id, e);
            unregisterServant(id);
            throw e;
        }
    } catch (Exception e) {
        log.error("Exception on " + req);
        __cb.ice_exception(e);
    } catch (Throwable t) {
        log.error("Throwable on " + req);
        RuntimeException rt = new RuntimeException("Throwable raised on " + req);
        rt.initCause(t);
        throw rt;
    }
}

From source file:org.apache.hadoop.mapred.StatusHttpServer.java

private static RuntimeException makeRuntimeException(String msg, Throwable cause) {
    RuntimeException result = new RuntimeException(msg);
    if (cause != null) {
        result.initCause(cause);
    }/* ww  w.j a  v a2  s  .c  o  m*/
    return result;
}

From source file:org.cesecore.keys.util.KeyTools.java

/**
 * create the subject key identifier./*from   w  ww .  j  ava 2s .c  o  m*/
 * 
 * @param pubKey
 *            the public key
 * 
 * @return SubjectKeyIdentifer asn.1 structure
 */
public static SubjectKeyIdentifier createSubjectKeyId(final PublicKey pubKey) {
    try {
        final ASN1Sequence keyASN1Sequence;
        ASN1InputStream pubKeyAsn1InputStream = new ASN1InputStream(
                new ByteArrayInputStream(pubKey.getEncoded()));
        try {
            final Object keyObject = pubKeyAsn1InputStream.readObject();
            if (keyObject instanceof ASN1Sequence) {
                keyASN1Sequence = (ASN1Sequence) keyObject;
            } else {
                // PublicKey key that don't encode to a ASN1Sequence. Fix this by creating a BC object instead.
                final PublicKey altKey = (PublicKey) KeyFactory.getInstance(pubKey.getAlgorithm(), "BC")
                        .translateKey(pubKey);
                ASN1InputStream altKeyAsn1InputStream = new ASN1InputStream(
                        new ByteArrayInputStream(altKey.getEncoded()));
                try {
                    keyASN1Sequence = (ASN1Sequence) altKeyAsn1InputStream.readObject();
                } finally {
                    altKeyAsn1InputStream.close();
                }
            }
            X509ExtensionUtils x509ExtensionUtils = new BcX509ExtensionUtils();
            return x509ExtensionUtils.createSubjectKeyIdentifier(new SubjectPublicKeyInfo(keyASN1Sequence));
        } finally {
            pubKeyAsn1InputStream.close();
        }
    } catch (Exception e) {
        final RuntimeException e2 = new RuntimeException("error creating key"); // NOPMD
        e2.initCause(e);
        throw e2;
    }
}

From source file:org.ejbca.util.keystore.KeyTools.java

/**
 * create the subject key identifier./*from   w w  w. j  ava  2 s.c om*/
 *
 * @param pubKey the public key
 *
 * @return SubjectKeyIdentifer asn.1 structure
 */
public static SubjectKeyIdentifier createSubjectKeyId(final PublicKey pubKey) {
    try {
        final ASN1Sequence keyASN1Sequence;
        final Object keyObject = new ASN1InputStream(new ByteArrayInputStream(pubKey.getEncoded()))
                .readObject();
        if (keyObject instanceof ASN1Sequence) {
            keyASN1Sequence = (ASN1Sequence) keyObject;
        } else {
            // PublicKey key that don't encode to a ASN1Sequence. Fix this by creating a BC object instead.
            final PublicKey altKey = (PublicKey) KeyFactory.getInstance(pubKey.getAlgorithm(), "BC")
                    .translateKey(pubKey);
            keyASN1Sequence = (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(altKey.getEncoded()))
                    .readObject();
        }
        return new SubjectKeyIdentifier(new SubjectPublicKeyInfo(keyASN1Sequence));
    } catch (Exception e) {
        final RuntimeException e2 = new RuntimeException("error creating key"); // NOPMD
        e2.initCause(e);
        throw e2;
    }
}

From source file:org.sakaiproject.metaobj.shared.mgt.factories.FieldValueWrapperFactoryImpl.java

public FieldValueWrapper wrapInstance(Class clazz) {
    Class wrapperClass = (Class) wrappedClassMap.get(clazz);

    FieldValueWrapper returnedWrapper = null;

    try {/*from ww w . j  a v a2  s  .  c o m*/
        returnedWrapper = (FieldValueWrapper) wrapperClass.newInstance();
    } catch (InstantiationException e) {
        RuntimeException exp = new IllegalArgumentException("Invalid wrapper class");
        exp.initCause(e);
        throw exp;
    } catch (IllegalAccessException e) {
        RuntimeException exp = new IllegalArgumentException("Invalid wrapper class");
        exp.initCause(e);
        throw exp;
    }

    return returnedWrapper;
}

From source file:org.tinygroup.commons.tools.Assert.java

/** ??? */
public static <T> T unexpectedException(Throwable e, String message, Object... args) {
    RuntimeException exception = UNEXPECTED_FAILURE
            .newInstance(getMessage(message, args, "[Assertion failed] - unexpected exception is thrown"));

    exception.initCause(e);

    throw exception;
}