Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.uci.ics.asterix.result.ResultUtils.java

public static String buildParseExceptionMessage(Throwable e, String query) {
    StringBuilder errorMessage = new StringBuilder();
    String message = e.getMessage();
    message = message.replace("<", "&lt");
    message = message.replace(">", "&gt");
    errorMessage.append("SyntaxError: " + message + "\n");
    int pos = message.indexOf("line");
    if (pos > 0) {
        Pattern p = Pattern.compile("\\d+");
        Matcher m = p.matcher(message);
        if (m.find(pos)) {
            int lineNo = Integer.parseInt(message.substring(m.start(), m.end()));
            String[] lines = query.split("\n");
            if (lineNo > lines.length) {
                errorMessage.append("===> &ltBLANK LINE&gt \n");
            } else {
                String line = lines[lineNo - 1];
                errorMessage.append("==> " + line);
            }/*from  www. j  av a2s .  c  o  m*/
        }
    }
    return errorMessage.toString();
}

From source file:com.evolveum.midpoint.gui.api.component.result.OpResult.java

public static OpResult getOpResult(PageBase page, OperationResult result) {
    OpResult opResult = new OpResult();
    Validate.notNull(result, "Operation result must not be null.");
    Validate.notNull(result.getStatus(), "Operation result status must not be null.");

    if (result.getCause() != null && result.getCause() instanceof CommonException) {
        LocalizableMessage localizableMessage = ((CommonException) result.getCause()).getUserFriendlyMessage();
        if (localizableMessage != null) {
            opResult.message = WebComponentUtil.resolveLocalizableMessage(localizableMessage, page);

            // Exclamation code:
            //                String key = localizableMessage.getKey() != null ? localizableMessage.getKey() : localizableMessage.getFallbackMessage();
            //              StringResourceModel stringResourceModel = new StringResourceModel(key, page).setModel(new Model<String>()).setDefaultValue(localizableMessage.getFallbackMessage())
            //            .setParameters(localizableMessage.getArgs());
            //              opResult.message = stringResourceModel.getString();
        }//from  w ww  .  j  a v a  2  s .  co  m
    }

    if (opResult.message == null) {
        opResult.message = result.getMessage();
    }
    opResult.operation = result.getOperation();
    opResult.status = result.getStatus();
    opResult.count = result.getCount();
    opResult.userFriendlyMessage = result.getUserFriendlyMessage();

    if (result.getCause() != null) {
        Throwable cause = result.getCause();
        opResult.exceptionMessage = cause.getMessage();

        Writer writer = new StringWriter();
        cause.printStackTrace(new PrintWriter(writer));
        opResult.exceptionsStackTrace = writer.toString();
    }

    if (result.getParams() != null) {
        for (Map.Entry<String, Collection<String>> entry : result.getParams().entrySet()) {
            String paramValue = null;
            Collection<String> values = entry.getValue();
            if (values != null) {
                paramValue = values.toString();
            }

            opResult.getParams().add(new Param(entry.getKey(), paramValue));
        }
    }

    if (result.getContext() != null) {
        for (Map.Entry<String, Collection<String>> entry : result.getContext().entrySet()) {
            String contextValue = null;
            Collection<String> values = entry.getValue();
            if (values != null) {
                contextValue = values.toString();
            }

            opResult.getContexts().add(new Context(entry.getKey(), contextValue));
        }
    }

    if (result.getSubresults() != null) {
        for (OperationResult subresult : result.getSubresults()) {
            OpResult subOpResult = OpResult.getOpResult(page, subresult);
            opResult.getSubresults().add(subOpResult);
            subOpResult.parent = opResult;
            if (subOpResult.getBackgroundTaskOid() != null) {
                opResult.backgroundTaskOid = subOpResult.getBackgroundTaskOid();
            }
        }
    }

    if (result.getBackgroundTaskOid() != null) {
        opResult.backgroundTaskOid = result.getBackgroundTaskOid();
    }

    try {
        OperationResultType resultType = result.createOperationResultType();
        ObjectFactory of = new ObjectFactory();
        opResult.xml = page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType));
    } catch (SchemaException | RuntimeException ex) {
        String m = "Can't create xml: " + ex;
        //         error(m);
        opResult.xml = "<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>";
        //            throw ex;
    }
    return opResult;
}

From source file:com.zenoss.zenpacks.zenjmx.call.Utility.java

public static void debugStack(Throwable e) {
    if (!_logger.isDebugEnabled())
        return;//from w  w  w .ja v  a 2 s.  c om
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    e.printStackTrace(ps);
    ps.flush();
    String stackTrace = baos.toString();
    _logger.debug(e.getMessage() + "\n" + stackTrace);
}

From source file:net.sf.ehcache.distribution.RMISynchronousCacheReplicator.java

/**
 * Does the actual RMI remote call//from  w  ww.  ja  va  2  s. c  om
 *
 * @param element
 * @param cache
 * @throws RemoteCacheException if anything goes wrong with the remote call
 */
private static void replicatePutNotification(Ehcache cache, Element element) throws RemoteCacheException {
    List cachePeers = listRemoteCachePeers(cache);
    for (int i = 0; i < cachePeers.size(); i++) {
        CachePeer cachePeer = (CachePeer) cachePeers.get(i);
        try {
            cachePeer.put(element);
        } catch (Throwable t) {
            throw new RemoteCacheException("Error doing put to remote peer. Message was: " + t.getMessage());
        }
    }
}

From source file:net.sf.ehcache.distribution.RMISynchronousCacheReplicator.java

/**
 * Does the actual RMI remote call//from   w w w  .j a  v a2  s . co  m
 *
 * @param key
 * @param cache
 * @throws RemoteCacheException if anything goes wrong with the remote call
 */
private static void replicateRemovalNotification(Ehcache cache, Serializable key) throws RemoteCacheException {
    List cachePeers = listRemoteCachePeers(cache);
    for (int i = 0; i < cachePeers.size(); i++) {
        CachePeer cachePeer = (CachePeer) cachePeers.get(i);
        try {
            cachePeer.remove(key);
        } catch (Throwable e) {
            throw new RemoteCacheException("Error doing remove to remote peer. Message was: " + e.getMessage());
        }
    }
}

From source file:com.apptentive.android.sdk.module.metric.MetricModule.java

/**
 * Used for internal error reporting when we intercept a Throwable that may have otherwise caused a crash.
 *
 * @param context     The context from which this method was called.
 * @param throwable   An optional throwable that was caught, and which we want to log.
 * @param description An optional description of what happened.
 * @param extraData   Any extra data that may have contributed to the Throwable being thrown.
 *//*from w w w .  j a  v  a  2  s.co  m*/
public static void sendError(Context context, Throwable throwable, String description, String extraData) {
    Event.EventLabel type = Event.EventLabel.error;
    try {
        JSONObject data = new JSONObject();
        data.put("thread", Thread.currentThread().getName());
        if (throwable != null) {
            JSONObject exception = new JSONObject();
            exception.put("message", throwable.getMessage());
            exception.put("stackTrace", Util.stackTraceAsString(throwable));
            data.put(KEY_EXCEPTION, exception);
        }
        if (description != null) {
            data.put("description", description);
        }
        if (extraData != null) {
            data.put("extraData", extraData);
        }
        Configuration config = Configuration.load(context);
        if (config.isMetricsEnabled()) {
            Log.v("Sending Error Metric: %s, data: %s", type.getLabelName(), data.toString());
            Event event = new Event(type.getLabelName(), data);
            EventManager.sendEvent(context, event);
        }
    } catch (Exception e) {
        // Since this is the last place in Apptentive code we can catch exceptions, we must catch all other Exceptions to
        // prevent the app from crashing.
        Log.w("Error creating Error Metric. Nothing we can do but log this.", e);
    }
}

From source file:com.funambol.framework.tools.WBXMLTools.java

/**
 * Converts a WBXML message into the corresponding XML message.
 *
 * @param msg the message to convert - NOT NULL
 * @param charset the characte set used for the encoding. If the
 * value is null, the character set defined in the wbxml is used
 * otherwise, UTF-8 is ised./*from  w  w w.  ja  va  2s . c o  m*/
 *
 * @return the XML message or NULL if an error occurred
 *
 * @throws Sync4jException in case of parser errors
 */
public static String wbxmlToXml(final byte[] msg, String charset) throws Sync4jException {

    ByteArrayInputStream in = null;
    try {
        in = new ByteArrayInputStream(msg);

        SyncMLParser parser = new SyncMLParser(in, charset);

        return parseWBXML(parser);
    } catch (Throwable t) {
        throw new Sync4jException(t.getMessage(), t);
    }
}

From source file:de.jcup.egradle.eclipse.util.EclipseUtil.java

public static String resolveMessageIfNotSet(String message, Throwable cause) {
    if (message == null) {
        if (cause == null) {
            message = "Unknown";
        } else {/*w  w  w . j  av  a2  s  .com*/
            message = cause.getMessage();
        }
    }
    return message;
}

From source file:Main.java

public static String getCompressedStackTrace(Throwable t, int startAt, int limit) {
    try {//from   ww w  . java 2 s.co  m
        StackTraceElement[] stackTrace = t.getStackTrace();
        if (stackTrace.length < startAt) {
            return "";
        }
        StringBuilder sb = new StringBuilder("");
        for (int i = startAt; i < stackTrace.length && i < startAt + limit; i++) {
            StackTraceElement element = stackTrace[i];
            String classname = element.getClassName();
            String cnShort;
            boolean showLineNumber = true;
            boolean breakAfter = false;
            if (classname.startsWith("com.vuze.android.remote.")) {
                cnShort = classname.substring(24, classname.length());
            } else if (classname.equals("android.os.Handler")) {
                showLineNumber = false;
                cnShort = "Handler";
            } else if (classname.equals("android.os.Looper")) {
                showLineNumber = false;
                cnShort = "Looper";
                breakAfter = true;
            } else if (classname.length() < 9) { // include full if something like aa.ab.ac
                cnShort = classname;
            } else {
                int len = classname.length();
                int start = len > 14 ? len - 14 : 0;

                int pos = classname.indexOf('.', start);
                if (pos >= 0) {
                    start = pos + 1;
                }
                cnShort = classname.substring(start, len);
            }
            if (i != startAt) {
                sb.append(", ");
            }
            sb.append(cnShort);
            sb.append('.');
            sb.append(element.getMethodName());
            if (showLineNumber) {
                sb.append(':');
                sb.append(element.getLineNumber());
            }
            if (breakAfter) {
                break;
            }
        }
        Throwable cause = t.getCause();
        if (cause != null) {
            sb.append("\n|Cause ");
            sb.append(cause.getClass().getSimpleName());
            if (cause instanceof Resources.NotFoundException || cause instanceof RuntimeException) {
                sb.append(' ');
                sb.append(cause.getMessage());
            }
            sb.append(' ');
            sb.append(getCompressedStackTrace(cause, 0, 9));
        }
        return sb.toString();
    } catch (Throwable derp) {
        return "derp " + derp.getClass().getSimpleName();
    }
}

From source file:cn.edu.wyu.documentviewer.model.DocumentInfo.java

public static FileNotFoundException asFileNotFoundException(Throwable t) throws FileNotFoundException {
    if (t instanceof FileNotFoundException) {
        throw (FileNotFoundException) t;
    }//from   www.ja va  2 s .c o  m
    final FileNotFoundException fnfe = new FileNotFoundException(t.getMessage());
    fnfe.initCause(t);
    throw fnfe;
}