Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:Main.java

/**
 * make a useful message from an exception without the stack track
 *///from  w w w  . j  av a2  s.co m
public static String formatException(String message, Exception e) {
    StringBuilder builder = new StringBuilder();
    if (message != null) {
        builder.append(message);
        if (e != null) {
            builder.append(" - ");
        }
    }

    if (e != null) {
        builder.append(e.getClass().getSimpleName());

        String exceptionMessage = e.getMessage();
        if (exceptionMessage != null) {
            builder.append(": ");
            builder.append(exceptionMessage);
        }

        for (Throwable cause = e.getCause(); cause != null; cause = cause.getCause()) {
            builder.append(" (cause ");
            builder.append(cause.getClass().getSimpleName());
            String causeMessage = e.getMessage();
            if (causeMessage != null) {
                builder.append(": ");
                builder.append(exceptionMessage);
            }
            builder.append(")");
        }
    }

    return builder.toString();
}

From source file:net.naijatek.myalumni.util.mail.SendMailUtil.java

public static void notifyAdminAboutNewMember(MemberVO memberVO, SystemConfigVO sysConfigVO) throws Exception {

    try {//  w w w  .ja v a  2 s.co m
        Map<String, String> map = new HashMap<String, String>();

        map.put("firstName", memberVO.getFirstName());
        map.put("lastName", memberVO.getLastName());
        map.put("yearIn", String.valueOf(memberVO.getYearIn()));
        map.put("yearOut", String.valueOf(memberVO.getYearOut()));
        map.put("schoolName", StringUtil.safeString(sysConfigVO.getOrganizationName()));
        map.put("serverName", StringUtil.safeString(sysConfigVO.getServerUrl()));
        map.put("adminSignature", StringUtil.safeString(sysConfigVO.getAdminSignature()));

        String subjectTemplatePrefix = TEMPLATE_NOTIFY_ADMIN_ABOUT_NEW_MEMBER_SUBJECT + "-text."
                + TEMPLATE_EXTENSION;
        String bodyTemplatePrefix = TEMPLATE_NOTIFY_ADMIN_ABOUT_NEW_MEMBER_BODY + "-text." + TEMPLATE_EXTENSION;
        new FreeMarkerTemplateMailerImpl(mailSender, configuration).mail(sysConfigVO.getOrgEmail(), map,
                bodyTemplatePrefix, subjectTemplatePrefix);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("notifyAdminAboutNewMember: " + e.getMessage());
        throw new MailServerException("Error encountered sendPasswordReminderMail " + e.getCause().toString());
    }

}

From source file:com.oeg.oops.VocabUtils.java

/**
 * Given a vocabulary, this method fills its lov page.
 * @param v/*from ww w. j a v  a 2 s . co m*/
 * @return true if the vocabulary is in LOV. False otherwise.
 * Method created by mpoveda
 */
public static boolean getLOVPage(Vocabulary v) {
    try {
        Query queryLOV = QueryFactory.create(Queries.isVocabInLOV(v.getUri()), Syntax.syntaxARQ);
        //            System.out.println(queryLOV);
        // Execute the query and obtain results
        QueryExecution qe = QueryExecutionFactory.sparqlService(Queries.LOVEndpoint, queryLOV);
        ResultSet results = qe.execSelect();
        if (results.hasNext()) {
            QuerySolution qs = results.next();
            v.setPrefix(qs.getLiteral("vocabPrefix").toString());
            v.setLovURI("http://lov.okfn.org/dataset/lov/details/vocabulary_" + v.getPrefix() + ".html");
            qe.close();
            return true;
        }
        qe.close();
        return false;
    } catch (java.lang.Exception d) {
        System.err.println("exc query en VocabInLOV: " + d.getMessage() + d.getCause().getMessage());
        return false;
    }
}

From source file:net.naijatek.myalumni.util.mail.SendMailUtil.java

/**
 * Notifies the member that they have an email to_email view.
 * //from   w ww.  j av a2s .  c o  m
 * @param pm PrivateMessage
 * @param to String
 * @throws MessagingException
 * @throws Exception
 */
public static void adminNewMessageNotification(final SystemConfigVO sysConfig, final String toEmail)
        throws Exception { //PROOF READ
    try {
        Map<String, String> map = new HashMap<String, String>();
        map.put("orgName", StringUtil.safeString(sysConfig.getOrganizationName()));
        map.put("serverName", StringUtil.safeString(sysConfig.getServerUrl()));
        map.put("adminSignature", StringUtil.safeString(sysConfig.getAdminSignature()));

        String subjectTemplatePrefix = TEMPLATE_NEW_ADMIN_MESSAGE_SUBJECT + "-text." + TEMPLATE_EXTENSION;
        String bodyTemplatePrefix = TEMPLATE_NEW_ADMIN_MESSAGE_BODY + "-text." + TEMPLATE_EXTENSION;
        new FreeMarkerTemplateMailerImpl(mailSender, configuration).mail(toEmail, map, bodyTemplatePrefix,
                subjectTemplatePrefix);
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error("adminNewMessageNotification: " + ex.getMessage());
        throw new MailServerException(
                "Error encountered when sending adminNewMessageNotification " + ex.getCause().toString());
    }

}

From source file:com.vmware.bdd.cli.commands.CommandsUtils.java

public static String getExceptionMessage(Exception e) {
    if (e.getCause() == null) {
        return e.getMessage();
    } else {//  ww w  .j ava2  s . c  o m
        return getRootCause(e).getMessage();
    }
}

From source file:net.naijatek.myalumni.util.mail.SendMailUtil.java

/**
   * Notifies the member that they have an email to_email view.
   * //  w ww .ja  va2s.  c  o  m
   * @param pm PrivateMessage
   * @param to String
   * @throws MessagingException
   * @throws Exception
   */
public static void memberNewMessageNotification(final PrivateMessageVO pm, final SystemConfigVO sysConfig,
        final String toEmail) throws Exception { //PROOF READ
    try {
        Map<String, String> map = new HashMap<String, String>();
        map.put("firstName", pm.getMessageToMember().getFirstName());
        map.put("lastName", pm.getMessageToMember().getLastName());
        map.put("orgName", StringUtil.safeString(sysConfig.getOrganizationName()));
        map.put("serverName", StringUtil.safeString(sysConfig.getServerUrl()));
        map.put("adminSignature", StringUtil.safeString(sysConfig.getAdminSignature()));

        String subjectTemplatePrefix = TEMPLATE_NEW_MESSAGE_SUBJECT + "-text." + TEMPLATE_EXTENSION;
        String bodyTemplatePrefix = TEMPLATE_NEW_MESSAGE_BODY + "-text." + TEMPLATE_EXTENSION;
        new FreeMarkerTemplateMailerImpl(mailSender, configuration).mail(toEmail, map, bodyTemplatePrefix,
                subjectTemplatePrefix);
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error("memberNewMessageNotification: " + ex.getMessage());
        throw new MailServerException(
                "Error encountered when sending memberNewMessageNotification " + ex.getCause().toString());
    }

}

From source file:net.naijatek.myalumni.util.mail.SendMailUtil.java

public static void sendProfileChangeNotificationMail(String recipient, String fullName,
        SystemConfigVO sysConfig, String reasonForUpdate) throws MailServerException {

    try {//from   w  w  w .  j  a va 2  s  . c om
        Map<String, String> map = new HashMap<String, String>();

        map.put("fullName", fullName);
        map.put("serverName", StringUtil.safeString(sysConfig.getServerUrl()));
        map.put("adminSignature", StringUtil.safeString(sysConfig.getAdminSignature()));
        map.put("reasonForUpdate", reasonForUpdate);

        String subjectTemplatePrefix = TEMPLATE_PROFILE_CHANGED_SUBJECT + "-text." + TEMPLATE_EXTENSION;
        String bodyTemplatePrefix = TEMPLATE_PROFILE_CHANGED_BODY + "-text." + TEMPLATE_EXTENSION;
        new FreeMarkerTemplateMailerImpl(mailSender, configuration).mail(recipient, map, bodyTemplatePrefix,
                subjectTemplatePrefix);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("sendProfileChangeNotificationMail: " + e.getMessage());
        throw new MailServerException(
                "Error encountered when sending email to remind user of password " + e.getCause().toString());
    }
}

From source file:br.com.nordestefomento.jrimum.utilix.Field.java

private static Exception getGenericReadError(Exception e, String value) {

    StackTraceElement[] stackTrace = e.getStackTrace();
    e = new RuntimeException("VALOR INV?LIDO [ " + value + " ]!\nCausado por: " + e.getCause());
    e.setStackTrace(stackTrace);/*from w w w. j  a  va 2  s .c o m*/

    return e;
}

From source file:com.vmware.bdd.cli.commands.CommandsUtils.java

private static Throwable getRootCause(Exception e) {
    Throwable cause = e.getCause();
    Throwable rootCause = null;//from ww  w.  j a  v  a 2 s  . com
    while (cause != null) {
        rootCause = cause;
        cause = cause.getCause();
    }
    return rootCause;
}

From source file:com.comcast.cns.tools.CQSHandler.java

public static boolean doesQueueNotExist(Exception ex) {

    boolean doesNotExist = false;

    if (ex instanceof AmazonServiceException && ((AmazonServiceException) ex).getStatusCode() == 400) {
        doesNotExist = true;/*from w ww .  ja  va 2s .c  om*/
    } else if (ex instanceof AmazonServiceException
            && ((AmazonServiceException) ex).getErrorCode().equals("NonExistentQueue")) {
        doesNotExist = true;
    } else if (ex.getCause() instanceof HttpHostConnectException) {
        doesNotExist = false;
    } else if (ex instanceof CMBException) {
        doesNotExist = false;
    }

    return doesNotExist;
}