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:mondrian.gui.Workbench.java

/**
 * @param args the command line arguments
 *///from   w  w  w .jav a2 s .c  o  m
public static void main(String args[]) {
    Workbench w = null;
    try {
        w = new Workbench();
        w.parseArgs(args);
        w.setSize(800, 600);
        // if user specified a file to open, do so now.
        if (w.openFile != null) {
            File f = new File(w.openFile);
            if (f.canRead()) {
                w.openSchemaFrame(f.getAbsoluteFile(),
                        // parameter to indicate this is a new or existing
                        // catalog file
                        false);
            }
        }
        w.setVisible(true);
    } catch (Throwable ex) {
        if (w != null) {
            JOptionPane.showMessageDialog(w,
                    w.getResourceConverter().getFormattedString("workbench.main.uncoverable_error",
                            "Pentaho Schema Workbench has encountered an unrecoverable error. \n{0}",
                            ex.getLocalizedMessage()),
                    w.getResourceConverter().getString("workbench.main.uncoverable_error.title",
                            "PSW Fatal Error"),
                    JOptionPane.ERROR_MESSAGE);
        }
        LOGGER.error("main", ex);
    }
}

From source file:Main.java

public static void logException(String tag, Throwable ex) {
    Log.e(tag, ex.getLocalizedMessage(), ex);
}

From source file:Main.java

public static void showErrorMessage(Context context, Throwable ex) {
    Toast.makeText(context, ex.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}

From source file:Main.java

public static void onError(String tag, Throwable e) {
    Log.e(tag, e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
}

From source file:Main.java

public static void showException(Context parent, Throwable ex) {
    if (ex != null) {
        Log.e(parent.getClass().getSimpleName(), ex.getLocalizedMessage(), ex);
        new AlertDialog.Builder(parent).setTitle("Error").setMessage(ex.getLocalizedMessage())
                .setNeutralButton("Close", null).show();
    }/*  w  ww .  j a  v a  2 s  .  c  o m*/
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T newInstance(@NonNull Class<T> cls) {
    final Constructor ctor = getDefaultConstructor(cls);
    try {//from   www.ja v  a 2s.  co  m
        return (T) ctor.newInstance();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException("Failed to instantiate " + cls.getName() + ": " + t.getLocalizedMessage());
    }
}

From source file:it.geosolutions.tools.io.file.reader.TextReader.java

/**
 * Get the contents of a {@link File} as a String using the specified character encoding.
 * /*from   ww w  .j a  v  a2 s  .c o  m*/
 * @param file
 *            {@link File} to read from
 * @param encoding
 *            IANA encoding
 * @return a {@link String} containig the content of the {@link File} or
 *         <code>null<code> if an error happens.
 */
public static String toString(final File file, final String encoding) {
    Objects.notNull(file);
    if (!file.isFile() || !file.canRead() || !file.exists())
        return null;
    InputStream stream = null;
    try {
        if (encoding == null)
            return org.apache.commons.io.IOUtils.toString(new FileInputStream(file));
        else
            return org.apache.commons.io.IOUtils.toString(new FileInputStream(file), encoding);
    } catch (Throwable e) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(e.getLocalizedMessage(), e);
        return null;
    } finally {
        if (stream != null)
            try {
                stream.close();
            } catch (Throwable e) {
                if (LOGGER.isTraceEnabled())
                    LOGGER.trace(e.getLocalizedMessage(), e);
            }
    }
}

From source file:org.ebayopensource.turmeric.eclipse.registry.consumer.utils.SOAMessageUtils.java

/**
 * Creates the multi status./* ww w .  ja  v  a2  s  .  co m*/
 *
 * @param pluginID the plugin id
 * @param code the code
 * @param children the children
 * @param description the description
 * @param throwable the throwable
 * @return the i status
 */
public static IStatus createMultiStatus(String pluginID, int code, IStatus[] children, String description,
        Throwable throwable) {
    if (description == null) {
        description = (throwable == null) || StringUtils.isNotBlank(throwable.getLocalizedMessage())
                ? UNKNOWN_ERROR
                : throwable.getLocalizedMessage();
    }
    if (pluginID == null)
        pluginID = Activator.PLUGIN_ID;

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

From source file:org.opencms.ui.components.CmsErrorDialog.java

/**
 * Shows the error dialog.<p>//w w  w  . j  a va2  s.c o m
 *
 * @param t the error to be displayed
 */
public static void showErrorDialog(Throwable t) {

    showErrorDialog(t.getLocalizedMessage(), t, null);
}

From source file:org.polymap.biotop.BiotopWorkbench.java

/**
 * Handle the given error by opening an error dialog and logging the given
 * message to the CorePlugin log./*from w  ww  .  j a  v a  2  s  .co m*/
 * 
 * @param src
 * @param msg The error message. If null, then a standard message is used.
 * @param e The reason of the error, must not be null.
 */
public static void handleError(String pluginId, Object src, final String msg, Throwable e) {
    log.error(msg, e);

    final Status status = new Status(IStatus.ERROR, pluginId, e.getLocalizedMessage(), e);
    CorePlugin.getDefault().getLog().log(status);

    final Display display = Polymap.getSessionDisplay();
    if (display == null) {
        log.error("No display -> no error message.");
        return;
    }

    Runnable runnable = new Runnable() {
        public void run() {
            try {
                Shell shell = PolymapWorkbench.getShellToParentOn();
                ErrorDialog dialog = new ErrorDialog(shell, "Achtung",
                        msg != null ? msg : "Fehler beim Ausfhren der Operation.", status,
                        IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR);
                //                dialog.setBlockOnOpen( true );
                dialog.open();
            } catch (Throwable ie) {
                log.warn(ie);
            }
        }
    };
    if (Display.getCurrent() != null) {
        runnable.run();
    } else {
        display.asyncExec(runnable);
    }
}