Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.tussle.main.Utility.java

public static JsonValue exceptionToJson(Throwable ex) {
    JsonValue topValue = new JsonValue(JsonValue.ValueType.object);
    JsonValue exceptionClass = new JsonValue(ex.getClass().toString());
    topValue.addChild("Exception Class", exceptionClass);
    if (ex.getLocalizedMessage() != null) {
        JsonValue exceptionMessage = new JsonValue(ex.getLocalizedMessage());
        topValue.addChild("Exception Message", exceptionMessage);
    }//from   ww w  . j  a v a 2  s  .c  om
    if (ex.getCause() != null) {
        JsonValue exceptionCause = new JsonValue(ex.getCause().toString());
        topValue.addChild("Exception Cause", exceptionCause);
    }
    JsonValue stackTrace = new JsonValue(JsonValue.ValueType.array);
    for (StackTraceElement element : ex.getStackTrace())
        stackTrace.addChild(new JsonValue(element.toString()));
    topValue.addChild("Stack Trace", stackTrace);
    return topValue;
}

From source file:com.clank.launcher.swing.SwingHelper.java

public static void addErrorDialogCallback(final Window owner, ListenableFuture<?> future) {
    Futures.addCallback(future, new FutureCallback<Object>() {
        @Override//from  ww  w.  j  a  v a2 s.com
        public void onSuccess(Object result) {
        }

        @Override
        public void onFailure(Throwable t) {
            if (t instanceof InterruptedException || t instanceof CancellationException) {
                return;
            }

            String message;
            if (t instanceof LauncherException) {
                message = t.getLocalizedMessage();
                t = t.getCause();
            } else {
                message = t.getLocalizedMessage();
                if (message == null) {
                    message = _("errors.genericError");
                }
            }
            log.log(Level.WARNING, "Task failed", t);
            SwingHelper.showErrorDialog(owner, message, _("errorTitle"), t);
        }
    }, SwingExecutor.INSTANCE);
}

From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.EclipseMessageUtils.java

/**
 * Creates the error status./* w  ww  .  j  av a2 s. c  o  m*/
 *
 * @param pluginID the plugin id
 * @param description the description
 * @param thrown the thrown
 * @return an instance of <code>IStatus</code> with Error severity level
 */
public static IStatus createErrorStatus(String pluginID, String description, Throwable thrown) {
    if (description == null) {
        description = (thrown == null) || StringUtils.isBlank(thrown.getLocalizedMessage())
                ? ERROR_MESSAGE_UNKNOWN
                : thrown.getLocalizedMessage();
    }
    if (pluginID == null)
        pluginID = UtilsActivator.SOA_PLUGIN_ID;
    return createAssertSafeStatus(IStatus.ERROR, pluginID, 0, description, thrown);
}

From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.EclipseMessageUtils.java

/**
 * Creates the multi status./*from ww  w . j a v a 2  s . c  om*/
 *
 * @param pluginID the plugin id
 * @param code the code
 * @param children the children
 * @param description the description
 * @param thrown the thrown
 * @return the i status
 */
public static IStatus createMultiStatus(String pluginID, int code, IStatus[] children, String description,
        Throwable thrown) {
    if (description == null) {
        description = (thrown == null) || StringUtils.isNotBlank(thrown.getLocalizedMessage())
                ? ERROR_MESSAGE_UNKNOWN
                : thrown.getLocalizedMessage();
    }
    if (pluginID == null)
        pluginID = UtilsActivator.SOA_PLUGIN_ID;

    if (children == null || children.length == 0) {
        return new MultiStatus(pluginID, code, description, thrown);
    } else {
        return new MultiStatus(pluginID, code, children, description, thrown);
    }
}

From source file:com.whizzosoftware.hobson.rest.v1.JSONMarshaller.java

public static JSONObject createErrorJSON(Throwable t) {
    return createErrorJSON(t.getLocalizedMessage());
}

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

/**
 * Extract the message in the root cause of the stack trace:
 *
 * @param e/*from  ww  w .  j  av  a2 s  .co m*/
 * @return error message string.
 */
private static String extractErrorMessage(Throwable e) {
    Throwable cause = getRootCause(e);
    String fullyQualifiedExceptionClassName = cause.getClass().getName();
    String[] hierarchySplits = fullyQualifiedExceptionClassName.split("\\.");
    //try returning the class without package qualification
    String exceptionClassName = hierarchySplits[hierarchySplits.length - 1];
    String localizedMessage = cause.getLocalizedMessage();
    if (localizedMessage == null) {
        localizedMessage = "Internal error. Please check instance logs for further details.";
    }
    return localizedMessage + " [" + exceptionClassName + "]";
}

From source file:org.geotools.gce.imagemosaic.CatalogManager.java

/**
 * Create a {@link SimpleFeatureType} from the specified configuration.
 * @param configurationBean/*from   ww  w.j a  va2  s .c o m*/
 * @param actualCRS
 * @return
 */
public static SimpleFeatureType createSchema(CatalogBuilderConfiguration runConfiguration, String name,
        CoordinateReferenceSystem actualCRS) {
    SimpleFeatureType indexSchema = null;
    SchemaType schema = null;
    String schemaAttributes = null;
    Indexer indexer = runConfiguration.getIndexer();
    if (indexer != null) {
        SchemasType schemas = indexer.getSchemas();
        Coverage coverage = IndexerUtils.getCoverage(indexer, name);
        if (coverage != null) {
            schema = IndexerUtils.getSchema(indexer, coverage);
        }
        if (schema != null) {
            schemaAttributes = schema.getAttributes();
        } else if (schemas != null) {
            List<SchemaType> schemaList = schemas.getSchema();
            // CHECK THAT
            if (!schemaList.isEmpty()) {
                schemaAttributes = schemaList.get(0).getAttributes();
            }
        }
    }
    if (schemaAttributes == null) {
        schemaAttributes = runConfiguration.getSchema(name);
    }
    if (schemaAttributes != null) {
        schemaAttributes = schemaAttributes.trim();
        // get the schema
        try {
            indexSchema = DataUtilities.createType(name, schemaAttributes);
            // override the crs in case the provided one was wrong or absent
            indexSchema = DataUtilities.createSubType(indexSchema, DataUtilities.attributeNames(indexSchema),
                    actualCRS);
        } catch (Throwable e) {
            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
            indexSchema = null;
        }
    }

    if (indexSchema == null) {
        // Proceed with default Schema
        final SimpleFeatureTypeBuilder featureBuilder = new SimpleFeatureTypeBuilder();
        featureBuilder.setName(runConfiguration.getParameter(Prop.INDEX_NAME));
        featureBuilder.setNamespaceURI("http://www.geo-solutions.it/");
        featureBuilder.add(runConfiguration.getParameter(Prop.LOCATION_ATTRIBUTE).trim(), String.class);
        featureBuilder.add("the_geom", Polygon.class, actualCRS);
        featureBuilder.setDefaultGeometry("the_geom");
        String timeAttribute = runConfiguration.getTimeAttribute();
        addAttributes(timeAttribute, featureBuilder, Date.class);
        indexSchema = featureBuilder.buildFeatureType();
    }
    return indexSchema;
}

From source file:models.data.providers.LogProvider.java

public static boolean deleteAllAppLogsOnDate(String archiveDate) {
    boolean success = true;

    try {/*from   ww  w.ja  v  a 2s  .com*/
        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate, VarUtils.LOG_FOLDER_NAME_APP_WITH_SLASH);
        // 2013094: add other log folders
        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate, VarUtils.LOG_FOLDER_NAME_ADHOC_WITH_SLASH);
        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate,
                VarUtils.LOG_FOLDER_NAME_NONESTARDARD_WITH_SLASH);

        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate,
                VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_AGGREGATION_RULES + "/");
        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate,
                VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_COMMANDS + "/");
        LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate,
                VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_NODE_GROUPS + "/");

        models.utils.LogUtils
                .printLogNormal("Success deleteAllAppLogsOnDate app logs with date " + archiveDate);
    } catch (Throwable t) {
        t.printStackTrace();
        models.utils.LogUtils
                .printLogNormal("Error occured in deleteAllAppLogsOnDate; ErrMsg: " + t.getLocalizedMessage());

        success = false;
    }
    return success;

}

From source file:net.sf.jabref.exporter.FileActions.java

/**
 * Saves the database to file, including only the entries included in the
 * supplied input array bes./*from   w w w . ja  v  a2  s  . c  o  m*/
 *
 * @return A List containing warnings, if any.
 */
public static SaveSession savePartOfDatabase(BibDatabase database, MetaData metaData, File file,
        JabRefPreferences prefs, BibEntry[] bes, Charset encoding, DatabaseSaveType saveType)
        throws SaveException {

    BibEntry be = null;
    boolean backup = prefs.getBoolean(JabRefPreferences.BACKUP);

    SaveSession session;
    try {
        session = new SaveSession(file, encoding, backup);
    } catch (IOException e) {
        throw new SaveException(e.getMessage(), e.getLocalizedMessage());
    }

    // Map to collect entry type definitions
    // that we must save along with entries using them.
    Map<String, EntryType> types = new TreeMap<>();

    // Define our data stream.
    try (VerifyingWriter fw = session.getWriter()) {

        if (saveType != DatabaseSaveType.PLAIN_BIBTEX) {
            // Write signature.
            FileActions.writeBibFileHeader(fw, encoding);
        }

        // Write preamble if there is one.
        FileActions.writePreamble(fw, database.getPreamble());

        // Write strings if there are any.
        FileActions.writeStrings(fw, database);

        // Write database entries. Take care, using CrossRefEntry-
        // Comparator, that referred entries occur after referring
        // ones. Apart from crossref requirements, entries will be
        // sorted as they appear on the screen.
        List<Comparator<BibEntry>> comparators = FileActions.getSaveComparators(true, metaData);

        // Use glazed lists to get a sorted view of the entries:
        List<BibEntry> sorter = new ArrayList<>(bes.length);
        Collections.addAll(sorter, bes);
        Collections.sort(sorter, new FieldComparatorStack<>(comparators));

        BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), true);

        for (BibEntry aSorter : sorter) {
            be = aSorter;

            // Check if we must write the type definition for this
            // entry, as well. Our criterion is that all non-standard
            // types (*not* customized standard types) must be written.
            EntryType tp = be.getType();
            if (EntryTypes.getStandardType(tp.getName()) == null) {
                types.put(tp.getName(), tp);
            }

            bibtexEntryWriter.write(be, fw);
            //only append newline if the entry has changed
            if (!be.hasChanged()) {
                fw.write(Globals.NEWLINE);
            }
        }

        // Write meta data.
        if ((saveType != DatabaseSaveType.PLAIN_BIBTEX) && (metaData != null)) {
            metaData.writeMetaData(fw);
        }

        // Write type definitions, if any:
        if (!types.isEmpty()) {
            for (Map.Entry<String, EntryType> stringBibtexEntryTypeEntry : types.entrySet()) {
                CustomEntryType tp = (CustomEntryType) stringBibtexEntryTypeEntry.getValue();
                CustomEntryTypesManager.save(tp, fw);
                fw.write(Globals.NEWLINE);
            }

        }
    } catch (Throwable ex) {
        session.cancel();
        //repairAfterError(file, backup, status);
        throw new SaveException(ex.getMessage(), ex.getLocalizedMessage(), be);
    }

    return session;

}

From source file:org.geoserver.rest.util.IOUtils.java

/**
 * Tries to convert a {@link URL} into a {@link File}. Return null if something bad happens
 * @param fileURL {@link URL} to be converted into a {@link File}.
 * @return {@link File} for this {@link URL} or null.
 *///  ww w. ja v  a 2  s. com
public static File URLToFile(URL fileURL) {
    inputNotNull(fileURL);
    try {

        final File retFile = DataUtilities.urlToFile(fileURL);
        return retFile;

    } catch (Throwable t) {
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.log(Level.FINE, t.getLocalizedMessage(), t);
    }
    return null;
}