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:com.unboundid.scim.sdk.SCIMEndpoint.java

/**
 * Extracts the exception message from the root cause of the exception if
 * possible.//from w ww  .j av  a  2  s  . com
 *
 * @param t the original Throwable that was caught. This may be null.
 * @return the exception message from the root cause of the exception, or
 *         null if the specified Throwable is null or the message cannot be
 *         determined.
 */
static String getExceptionMessage(final Throwable t) {
    if (t == null) {
        return null;
    }

    Throwable rootCause = StaticUtils.getRootCause(t);
    return rootCause.getMessage();
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

private static TableModel createTableModel(final IVisualizationCallback callback) {
    TableModel multicastDemandTableModel = new ClassAwareTableModel(
            new Object[1][netPlanViewTableHeader.length], netPlanViewTableHeader) {
        private static final long serialVersionUID = 1L;

        @Override/*ww w  .  ja va 2s .c o m*/
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            if (!callback.getVisualizationState().isNetPlanEditable())
                return false;
            if (columnIndex >= netPlanViewTableHeader.length)
                return true;
            if (getValueAt(rowIndex, columnIndex) == null)
                return false;

            return columnIndex == COLUMN_OFFEREDTRAFFIC || columnIndex >= netPlanViewTableHeader.length;
        }

        @Override
        public void setValueAt(Object newValue, int row, int column) {
            Object oldValue = getValueAt(row, column);

            /* If value doesn't change, exit from function */
            if (newValue.equals(oldValue))
                return;

            NetPlan netPlan = callback.getDesign();

            if (getValueAt(row, 0) == null)
                row = row - 1;
            final long demandId = (Long) getValueAt(row, 0);
            final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId);

            /* Perform checks, if needed */
            try {
                switch (column) {
                case COLUMN_OFFEREDTRAFFIC:
                    final double newOfferedTraffic = Double.parseDouble(newValue.toString());
                    if (newOfferedTraffic < 0)
                        throw new Net2PlanException("The demand offered traffic cannot be negative");
                    if (callback.getVisualizationState().isWhatIfAnalysisActive()) {
                        final WhatIfAnalysisPane whatIfPane = callback.getWhatIfAnalysisPane();
                        synchronized (whatIfPane) {
                            whatIfPane.whatIfDemandOfferedTrafficModified(demand, newOfferedTraffic);
                            if (whatIfPane.getLastWhatIfExecutionException() != null)
                                throw whatIfPane.getLastWhatIfExecutionException();
                            whatIfPane.wait(); // wait until the simulation ends
                            if (whatIfPane.getLastWhatIfExecutionException() != null)
                                throw whatIfPane.getLastWhatIfExecutionException();

                            final VisualizationState vs = callback.getVisualizationState();
                            Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs
                                    .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(
                                            new HashSet<>(callback.getDesign().getNetworkLayers()));
                            vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(),
                                    res.getSecond());
                            callback.updateVisualizationAfterNewTopology();
                        }
                    } else {
                        demand.setOfferedTraffic(newOfferedTraffic);
                        callback.updateVisualizationAfterChanges(
                                Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                        callback.getVisualizationState().pickMulticastDemand(demand);
                        callback.updateVisualizationAfterPick();
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    }
                    break;

                default:
                    break;
                }
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(), "Error modifying multicast demand");
                return;
            }

            /* Set new value */
            super.setValueAt(newValue, row, column);
        }
    };
    return multicastDemandTableModel;
}

From source file:com.msopentech.o365.outlookServices.OutlookServicesMethodsImpl.java

/**
 * Adds default callback that send future's result back to plugin
 *
 * @param future Future to add callback to
 * @param context Plugin context used to send future result back to plugin
 * @param resolver Dependency resolver, that used to serialize future results
 *///from  w  w  w  .java 2 s .c o m
static <T> void addCordovaCallback(final ListenableFuture<T> future, final CallbackContext context,
        final DependencyResolver resolver) {
    Futures.addCallback(future, new FutureCallback<T>() {
        @Override
        public void onSuccess(T t) {
            if (t != null) {
                String result = resolver.getJsonSerializer().serialize(t);
                context.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
            } else {
                context.sendPluginResult(new PluginResult(PluginResult.Status.OK));
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, throwable.getMessage()));
        }
    });
}

From source file:eu.stratosphere.pact.runtime.task.AbstractPactTask.java

/**
 * Closes the given stub using its {@link Stub#close()} method. If the close call produces
 * an exception, a new exception with a standard error message is created, using the encountered exception
 * as its cause./*from   ww w .j a v a 2s .  c  om*/
 * 
 * @param stub The user code instance to be closed.
 * 
 * @throws Exception Thrown, if the user code's close method produces an exception.
 */
public static void closeUserCode(Stub stub) throws Exception {
    try {
        stub.close();
    } catch (Throwable t) {
        throw new Exception("The user defined 'close()' method caused an exception: " + t.getMessage(), t);
    }
}

From source file:com.opendoorlogistics.core.utils.strings.Strings.java

/**
 * Gets the list of all messages from the exception and and the ancestor exception(s) that caused it. The list is returned in chronological order.
 * //from   w w w  .ja  v a2  s. c o m
 * @param e
 * @return
 */
public static List<String> getExceptionMessages(Throwable e) {
    // get reversed list of causes so its chronological
    ArrayList<Throwable> causes = new ArrayList<>();
    while (e != null) {
        causes.add(e);
        e = e.getCause();
    }
    Collections.reverse(causes);

    // get the list of messages
    ArrayList<String> messages = new ArrayList<>();

    ArrayList<String> ret = new ArrayList<>();
    for (Throwable exception : causes) {
        if (isEmpty(exception.getMessage()) == false) {
            String msg = exception.getMessage();

            // skip if part of the message has already been shown as its likely just the same message with
            // the exception class name added to the start
            boolean found = false;
            for (String shown : messages) {
                if (shown.length() > 3 && msg.toLowerCase().contains(shown.toLowerCase())) {
                    found = true;
                    break;
                }
            }

            if (!found) {
                // save to list of shown messages
                messages.add(msg);

                // only print the exception type if it gives the user some information
                if (exception.getClass() != Exception.class && exception.getClass() != RuntimeException.class) {
                    ret.add("Exception of type \"" + exception.getClass().getSimpleName() + "\" : " + msg);
                } else {
                    ret.add(msg);
                }
            }

        }
    }
    return ret;
}

From source file:com.oncore.calorders.core.utils.FormatHelper.java

/**
 * This method returns the stack trace of an exception
 *
 * @param throwable The exception/*from  w  ww.j  a va2  s  .  c om*/
 * @return The stack trace in string
 */
public static String getStackTrace(Throwable throwable) {
    StringBuilder trace = new StringBuilder();
    trace.append(throwable.getClass().getCanonicalName());
    trace.append("\n\t");

    trace.append(throwable.getMessage());
    trace.append("\n");

    for (StackTraceElement stackTrace : throwable.getStackTrace()) {
        trace.append(stackTrace.toString());
        trace.append("\n\t");
    }

    return trace.toString();
}

From source file:eu.stratosphere.pact.runtime.task.AbstractPactTask.java

/**
 * Opens the given stub using its {@link Stub#open(Configuration)} method. If the open call produces
 * an exception, a new exception with a standard error message is created, using the encountered exception
 * as its cause.//from   ww  w  . j  a v a 2s.co  m
 * 
 * @param stub The user code instance to be opened.
 * @param parameters The parameters supplied to the user code.
 * 
 * @throws Exception Thrown, if the user code's open method produces an exception.
 */
public static void openUserCode(Stub stub, Configuration parameters) throws Exception {
    try {
        stub.open(parameters);
    } catch (Throwable t) {
        throw new Exception(
                "The user defined 'open(Configuration)' method caused an exception: " + t.getMessage(), t);
    }
}

From source file:com.espertech.esper.core.service.EPServicesContextFactoryDefault.java

/**
 * Initialize event adapter service for config snapshot.
 * @param eventAdapterService is events adapter
 * @param configSnapshot is the config snapshot
 *///from  ww w .j av  a 2 s  .  c om
protected static void init(EventAdapterService eventAdapterService, ConfigurationInformation configSnapshot) {
    // Extract legacy event type definitions for each event type name, if supplied.
    //
    // We supply this information as setup information to the event adapter service
    // to allow discovery of superclasses and interfaces during event type construction for bean events,
    // such that superclasses and interfaces can use the legacy type definitions.
    Map<String, ConfigurationEventTypeLegacy> classLegacyInfo = new HashMap<String, ConfigurationEventTypeLegacy>();
    for (Map.Entry<String, String> entry : configSnapshot.getEventTypeNames().entrySet()) {
        String typeName = entry.getKey();
        String className = entry.getValue();
        ConfigurationEventTypeLegacy legacyDef = configSnapshot.getEventTypesLegacy().get(typeName);
        if (legacyDef != null) {
            classLegacyInfo.put(className, legacyDef);
        }
    }
    eventAdapterService.setClassLegacyConfigs(classLegacyInfo);
    eventAdapterService.setDefaultPropertyResolutionStyle(
            configSnapshot.getEngineDefaults().getEventMeta().getClassPropertyResolutionStyle());
    eventAdapterService.setDefaultAccessorStyle(
            configSnapshot.getEngineDefaults().getEventMeta().getDefaultAccessorStyle());

    for (String javaPackage : configSnapshot.getEventTypeAutoNamePackages()) {
        eventAdapterService.addAutoNamePackage(javaPackage);
    }

    // Add from the configuration the Java event class names
    Map<String, String> javaClassNames = configSnapshot.getEventTypeNames();
    for (Map.Entry<String, String> entry : javaClassNames.entrySet()) {
        // Add Java class
        try {
            String typeName = entry.getKey();
            eventAdapterService.addBeanType(typeName, entry.getValue(), false, true, true, true);
        } catch (EventAdapterException ex) {
            throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
        }
    }

    // Add from the configuration the XML DOM names and type def
    Map<String, ConfigurationEventTypeXMLDOM> xmlDOMNames = configSnapshot.getEventTypesXMLDOM();
    for (Map.Entry<String, ConfigurationEventTypeXMLDOM> entry : xmlDOMNames.entrySet()) {
        SchemaModel schemaModel = null;
        if ((entry.getValue().getSchemaResource() != null) || (entry.getValue().getSchemaText() != null)) {
            try {
                schemaModel = XSDSchemaMapper.loadAndMap(entry.getValue().getSchemaResource(),
                        entry.getValue().getSchemaText(), 2);
            } catch (Exception ex) {
                throw new ConfigurationException(ex.getMessage(), ex);
            }
        }

        // Add XML DOM type
        try {
            eventAdapterService.addXMLDOMType(entry.getKey(), entry.getValue(), schemaModel, true);
        } catch (EventAdapterException ex) {
            throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
        }
    }

    // Add maps in dependency order such that supertypes are added before subtypes
    Set<String> dependentMapOrder;
    try {
        Map<String, Set<String>> typesReferences = toTypesReferences(configSnapshot.getMapTypeConfigurations());
        dependentMapOrder = GraphUtil.getTopDownOrder(typesReferences);
    } catch (GraphCircularDependencyException e) {
        throw new ConfigurationException(
                "Error configuring engine, dependency graph between map type names is circular: "
                        + e.getMessage(),
                e);
    }

    Map<String, Properties> mapNames = configSnapshot.getEventTypesMapEvents();
    Map<String, Map<String, Object>> nestableMapNames = configSnapshot.getEventTypesNestableMapEvents();
    dependentMapOrder.addAll(mapNames.keySet());
    dependentMapOrder.addAll(nestableMapNames.keySet());
    try {
        for (String mapName : dependentMapOrder) {
            ConfigurationEventTypeMap mapConfig = configSnapshot.getMapTypeConfigurations().get(mapName);
            Properties propertiesUnnested = mapNames.get(mapName);
            if (propertiesUnnested != null) {
                Map<String, Object> propertyTypes = createPropertyTypes(propertiesUnnested);
                Map<String, Object> propertyTypesCompiled = EventTypeUtility
                        .compileMapTypeProperties(propertyTypes, eventAdapterService);
                eventAdapterService.addNestableMapType(mapName, propertyTypesCompiled, mapConfig, true, true,
                        true, false, false);
            }

            Map<String, Object> propertiesNestable = nestableMapNames.get(mapName);
            if (propertiesNestable != null) {
                Map<String, Object> propertiesNestableCompiled = EventTypeUtility
                        .compileMapTypeProperties(propertiesNestable, eventAdapterService);
                eventAdapterService.addNestableMapType(mapName, propertiesNestableCompiled, mapConfig, true,
                        true, true, false, false);
            }
        }
    } catch (EventAdapterException ex) {
        throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
    }

    // Add object-array in dependency order such that supertypes are added before subtypes
    Set<String> dependentObjectArrayOrder;
    try {
        Map<String, Set<String>> typesReferences = toTypesReferences(
                configSnapshot.getObjectArrayTypeConfigurations());
        dependentObjectArrayOrder = GraphUtil.getTopDownOrder(typesReferences);
    } catch (GraphCircularDependencyException e) {
        throw new ConfigurationException(
                "Error configuring engine, dependency graph between object array type names is circular: "
                        + e.getMessage(),
                e);
    }
    Map<String, Map<String, Object>> nestableObjectArrayNames = configSnapshot
            .getEventTypesNestableObjectArrayEvents();
    dependentObjectArrayOrder.addAll(nestableObjectArrayNames.keySet());
    try {
        for (String objectArrayName : dependentObjectArrayOrder) {
            ConfigurationEventTypeObjectArray objectArrayConfig = configSnapshot
                    .getObjectArrayTypeConfigurations().get(objectArrayName);
            Map<String, Object> propertyTypes = nestableObjectArrayNames.get(objectArrayName);
            propertyTypes = resolveClassesForStringPropertyTypes(propertyTypes);
            Map<String, Object> propertyTypesCompiled = EventTypeUtility.compileMapTypeProperties(propertyTypes,
                    eventAdapterService);
            eventAdapterService.addNestableObjectArrayType(objectArrayName, propertyTypesCompiled,
                    objectArrayConfig, true, true, true, false, false);
        }
    } catch (EventAdapterException ex) {
        throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
    }

    // Add plug-in event representations
    Map<URI, ConfigurationPlugInEventRepresentation> plugInReps = configSnapshot.getPlugInEventRepresentation();
    for (Map.Entry<URI, ConfigurationPlugInEventRepresentation> entry : plugInReps.entrySet()) {
        String className = entry.getValue().getEventRepresentationClassName();
        Class eventRepClass;
        try {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            eventRepClass = Class.forName(className, true, cl);
        } catch (ClassNotFoundException ex) {
            throw new ConfigurationException(
                    "Failed to load plug-in event representation class '" + className + "'", ex);
        }

        Object pluginEventRepObj;
        try {
            pluginEventRepObj = eventRepClass.newInstance();
        } catch (InstantiationException ex) {
            throw new ConfigurationException("Failed to instantiate plug-in event representation class '"
                    + className + "' via default constructor", ex);
        } catch (IllegalAccessException ex) {
            throw new ConfigurationException(
                    "Illegal access to instantiate plug-in event representation class '" + className
                            + "' via default constructor",
                    ex);
        }

        if (!(pluginEventRepObj instanceof PlugInEventRepresentation)) {
            throw new ConfigurationException("Plug-in event representation class '" + className
                    + "' does not implement the required interface "
                    + PlugInEventRepresentation.class.getName());
        }

        URI eventRepURI = entry.getKey();
        PlugInEventRepresentation pluginEventRep = (PlugInEventRepresentation) pluginEventRepObj;
        Serializable initializer = entry.getValue().getInitializer();
        PlugInEventRepresentationContext context = new PlugInEventRepresentationContext(eventAdapterService,
                eventRepURI, initializer);

        try {
            pluginEventRep.init(context);
            eventAdapterService.addEventRepresentation(eventRepURI, pluginEventRep);
        } catch (Throwable t) {
            throw new ConfigurationException("Plug-in event representation class '" + className + "' and URI '"
                    + eventRepURI + "' did not initialize correctly : " + t.getMessage(), t);
        }
    }

    // Add plug-in event type names
    Map<String, ConfigurationPlugInEventType> plugInNames = configSnapshot.getPlugInEventTypes();
    for (Map.Entry<String, ConfigurationPlugInEventType> entry : plugInNames.entrySet()) {
        String name = entry.getKey();
        ConfigurationPlugInEventType config = entry.getValue();
        eventAdapterService.addPlugInEventType(name, config.getEventRepresentationResolutionURIs(),
                config.getInitializer());
    }
}

From source file:edu.temple.cis3238.wiki.utils.StringUtils.java

/**
 *
 * @param e/*w w  w  .  ja  v  a  2  s .c o  m*/
 * @return
 */
public static final String stackStraceAsStringDetails(final Throwable e) {
    StringBuilder sb = new StringBuilder("");
    if (e != null) {
        final StringWriter stringWriter = new StringWriter();
        try {
            e.printStackTrace(new PrintWriter(stringWriter));
            sb.append(stringWriter.toString());
            sb.append("\nCause:");
            sb.append(e);
            Throwable t = e.getCause();
            while (t != null) {
                sb.append(t);
                sb.append("\n");
                t = t.getCause();
            }
        } catch (Exception exc) {
            sb.append(e.getMessage());
        } finally {
            return StringUtils.toS(sb.toString(), "Sorry.. full stack trace not available");
        }

    } else {
        LOG.warning("Exception null printing stack track");
        return "Null exception";
    }
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

public static void refreshTransfers(Context context) {
    Intent intent = new Intent(context, MainActivity.class).setAction(Constants.ACTION_SHOW_TRANSFERS)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    try {/*from w ww  .  ja v a2  s. c om*/
        context.startActivity(intent);
    } catch (Throwable t) {
        LOG.error(t.getMessage(), t);
    }
}