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.runwaysdk.manager.general.MainWindow.java

@Override
public void error(final Throwable throwable) {
    this.syncExec(new Runnable() {
        @Override//from w  w  w .  j  ava  2  s. c om
        public void run() {
            log.error(this, throwable);

            error(throwable.getLocalizedMessage());
        }
    });
}

From source file:org.geotools.gce.imagemosaic.catalog.GTDataStoreGranuleCatalog.java

@Override
public int removeGranules(Query query) {
    Utilities.ensureNonNull("query", query);
    query = mergeHints(query);//  ww  w.  j  av  a 2 s  .c o m
    final Lock lock = rwLock.writeLock();
    try {
        lock.lock();
        // check if the index has been cleared
        checkStore();
        String typeName = query.getTypeName();
        SimpleFeatureStore fs = null;
        try {
            // create a writer that appends this features
            fs = (SimpleFeatureStore) tileIndexStore.getFeatureSource(typeName);
            final int retVal = fs.getCount(query);
            fs.removeFeatures(query.getFilter());

            // update bounds
            bounds.put(typeName, tileIndexStore.getFeatureSource(typeName).getBounds());

            return retVal;

        } catch (Throwable e) {
            if (LOGGER.isLoggable(Level.SEVERE))
                LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            return -1;
        }
        // do your thing
    } finally {
        lock.unlock();

    }
}

From source file:org.n52.sos.encode.OwsEncoderv110.java

private void addExceptionMessages(StringBuilder exceptionText, Throwable exception) {
    exceptionText.append("[EXCEPTION]: \n");
    final String localizedMessage = exception.getLocalizedMessage();
    final String message = exception.getMessage();
    if (localizedMessage != null && message != null) {
        if (!message.equals(localizedMessage)) {
            JavaHelper.appendTextToStringBuilderWithLineBreak(exceptionText, message);
        }//from  w w  w  . j  a  v  a 2s.  c o  m
        JavaHelper.appendTextToStringBuilderWithLineBreak(exceptionText, localizedMessage);
    } else {
        JavaHelper.appendTextToStringBuilderWithLineBreak(exceptionText, localizedMessage);
        JavaHelper.appendTextToStringBuilderWithLineBreak(exceptionText, message);
    }

    //recurse cause if necessary
    if (exception.getCause() != null) {
        exceptionText.append("[CAUSED BY]\n");
        addExceptionMessages(exceptionText, exception.getCause());
    }

    //recurse SQLException if necessary
    if (exception instanceof SQLException) {
        SQLException sqlException = (SQLException) exception;
        if (sqlException.getNextException() != null) {
            exceptionText.append("[NEXT SQL EXCEPTION]\n");
            addExceptionMessages(exceptionText, sqlException.getNextException());
        }
    }
}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.UIUtil.java

/**
 * open the error dialog and display error stacktrace.
 *
 * @param parent the parent shell of the dialog, or <code>null</code> if none
 * @param dialogTitle the title to use for this dialog, or <code>null</code> to
 * indicate that the default title should be used,default is
 * "Problem Occurred"/* w  w w.  ja v a2 s  .  c om*/
 * @param message the message to show in this dialog, or <code>null</code> to
 * indicate that the exception's message should be shown as the
 * primary message
 * @param exception the exception used to display stackTrace ,or <code>null</code>
 * to indicate that the exception is not available,only
 * errorMessage will be shown.
 */
public static void showErrorDialog(final Shell parent, final String dialogTitle, final String message,
        final Throwable exception) {
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
            IStatus status = null;
            if (exception == null) {
                showErrorDialog(parent, "", dialogTitle, message);
                return;
            }
            if (exception instanceof CoreException) {
                status = ((CoreException) exception).getStatus();
            } else {
                final String reason;
                if (exception.getCause() != null) {
                    reason = exception.getCause().getLocalizedMessage();
                } else {
                    reason = exception.getLocalizedMessage();
                }

                MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 1,
                        StringUtils.defaultString(reason), null);
                status = multiStatus;
                String stackTrace = ExceptionUtils.getStackTrace(exception);
                BufferedReader br = new BufferedReader(new StringReader(stackTrace));
                String line = null;
                try {
                    while ((line = br.readLine()) != null) {
                        multiStatus.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, line, null));
                    }
                } catch (IOException ioex) {
                    ioex.printStackTrace();

                } finally {
                    IOUtils.closeQuietly(br);
                }
            }
            String finalMessage = message;
            if (StringUtils.isBlank(message)) {
                // The message is blank, try to have a message for it.
                finalMessage = StringUtils.isNotBlank(exception.getLocalizedMessage())
                        ? exception.getLocalizedMessage()
                        : exception.toString();
            }

            SOAErrorDialog.openError(parent, dialogTitle, finalMessage, status,
                    IStatus.ERROR | IStatus.WARNING);

        }

    };
    if (Display.getCurrent() == null) {
        // not running in a UI thread.
        new UIJob("Error Occured") {
            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                runnable.run();
                return Status.OK_STATUS;
            }
        }.schedule();
    } else {
        runnable.run();
    }

}

From source file:org.craftercms.cstudio.alfresco.dm.script.DmContentServiceScript.java

/**
 * update content asset from webform (template, css, js)
 *
 * @param site/*from   w w w .  ja va 2s  .c  o  m*/
 * @param path
 * @param content
 * @return content asset info
 * @throws ServiceException
 */
public ResultTO updateContentAsset(String site, String path, String content) {
    int slashIndex = path.lastIndexOf("/");
    String assetName = path.substring(slashIndex + 1);
    path = path.substring(0, slashIndex);
    /***************************************/

    Map<String, String> params = new FastMap<String, String>();
    params.put(DmConstants.KEY_SITE, site);
    params.put(DmConstants.KEY_PATH, path);
    params.put(DmConstants.KEY_FILE_NAME, assetName);
    params.put(DmConstants.KEY_CONTENT_TYPE, "");
    params.put(DmConstants.KEY_CREATE_FOLDERS, "true");
    params.put(DmConstants.KEY_UNLOCK, "true");

    String id = site + ":" + path + ":" + assetName + ":" + "";
    InputStream in = IOUtils.toInputStream(content);
    // processContent will close the input stream
    String fullPath = null;
    PersistenceManagerService persistenceManagerService = getServicesManager()
            .getService(PersistenceManagerService.class);
    ServicesConfig servicesConfig = getServicesManager().getService(ServicesConfig.class);
    NodeRef nodeRef = null;
    try {
        fullPath = servicesConfig.getRepositoryRootPath(site) + path + "/" + assetName;
        if (nodeRef != null) {
            persistenceManagerService.setSystemProcessing(fullPath, true);
        }
        DmContentService dmContentService = getServicesManager().getService(DmContentService.class);
        ResultTO result = dmContentService.processContent(id, in, false, params,
                DmConstants.CONTENT_CHAIN_ASSET);
        persistenceManagerService.transition(fullPath, ObjectStateService.TransitionEvent.SAVE);
        ResultTO resultTO = ScriptUtils.createSuccessResult(result.getItem());
        return resultTO;
    } catch (ContentNotAllowedException e) {
        return ScriptUtils.createFailureResult(CStudioConstants.HTTP_STATUS_IMAGE_SIZE_ERROR,
                e.getLocalizedMessage());
    } catch (AlfrescoRuntimeException e) {
        logger.error("Error processing content", e);
        Throwable cause = e.getCause();
        if (cause != null) {
            return ScriptUtils.createFailureResult(CStudioConstants.HTTP_STATUS_INTERNAL_SERVER_ERROR,
                    cause.getLocalizedMessage());
        }
        return ScriptUtils.createFailureResult(CStudioConstants.HTTP_STATUS_INTERNAL_SERVER_ERROR,
                e.getLocalizedMessage());
    } catch (Exception e) {
        logger.error("Error processing content", e);
        return ScriptUtils.createFailureResult(CStudioConstants.HTTP_STATUS_INTERNAL_SERVER_ERROR,
                e.getLocalizedMessage());
    } finally {
        if (nodeRef != null) {
            persistenceManagerService.setSystemProcessing(fullPath, false);
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.ui.pullrequest.CreatePullRequestModel.java

/**
 * Create pull request on a background thread
 * <p/>//from w  w w . j  a v a2s. c om
 * This method will first check to see if the local branch has a tracking branch:
 * yes:
 * push the commits to the remote tracking branch
 * no:
 * try create a remote branch matching the local branch name exactly, with the remote set to the GitRemote of
 * the target branch
 * <p/>
 * If push fails for whatever reason, stop and show an error message
 * <p/>
 * After we push the local branch, then create the pull request.  Pull request link should be returned
 * in a notification bubble
 */
public void createPullRequest() {
    /* verifying branch selections */
    final GitLocalBranch sourceBranch = this.getSourceBranch();
    final GitRemoteBranch targetBranch = this.getTargetBranch();

    if (sourceBranch == null) {
        // how did we get here? validation failed?
        notifyCreateFailedError(project,
                TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_ERRORS_SOURCE_EMPTY));
        return;
    }

    if (targetBranch == null) {
        // how did we get here? validation failed?
        notifyCreateFailedError(project,
                TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_ERRORS_TARGET_NOT_SELECTED));
        return;
    }

    if (targetBranch.equals(this.getRemoteTrackingBranch())) {
        // how did we get here? Didn't we filter you out?
        notifyCreateFailedError(project,
                TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_ERRORS_TARGET_IS_LOCAL_TRACKING));
        return;
    }

    //TODO Determine the correct/best way to get the remote url
    final String gitRemoteUrl = TfGitHelper.getTfGitRemote(gitRepository).getFirstUrl();
    final CreatePullRequestModel createModel = this;
    /* Let's keep all server interactions to a background thread */
    final Task.Backgroundable createPullRequestTask = new Task.Backgroundable(project,
            TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_DIALOG_TITLE), true,
            PerformInBackgroundOption.DEAF) {
        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            ListenableFuture<Pair<String, GitCommandResult>> pushResult = doPushCommits(gitRepository,
                    sourceBranch, targetBranch.getRemote(), progressIndicator);

            Futures.addCallback(pushResult, new FutureCallback<Pair<String, GitCommandResult>>() {
                @Override
                public void onSuccess(@Nullable Pair<String, GitCommandResult> result) {
                    if (result != null && StringUtils.isNotEmpty(result.getFirst())) {
                        final String title = createModel.getTitle();
                        final String description = createModel.getDescription();
                        final String branchNameOnRemoteServer = result.getFirst();

                        // get context from manager, we want to do this after push completes since credentials could have changed during the Git push
                        final ServerContext context = ServerContextManager.getInstance()
                                .getAuthenticatedContext(gitRemoteUrl, true);

                        if (context == null) {
                            notifyCreateFailedError(project, TfPluginBundle
                                    .message(TfPluginBundle.KEY_ERRORS_AUTH_NOT_SUCCESSFUL, gitRemoteUrl));
                            return;
                        }

                        doCreatePullRequest(project, context, title, description, branchNameOnRemoteServer,
                                targetBranch);
                    } else {
                        // I really don't have anything else to say, push failed, the title says it all
                        // I have no error message to be more specific
                        notifyPushFailedError(createModel.getProject(), StringUtils.EMPTY);
                    }
                }

                @Override
                public void onFailure(Throwable t) {
                    notifyPushFailedError(createModel.getProject(), t.getLocalizedMessage());
                }
            });
        }
    };

    createPullRequestTask.queue();
}

From source file:de.iteratec.iteraplan.presentation.dialog.GuiController.java

@ExceptionHandler(Throwable.class)
public ModelAndView handleIteraplanException(Throwable ex, HttpServletRequest req, HttpServletResponse resp) {

    ModelAndView mav = new ModelAndView("errorOutsideFlow");
    if (ex instanceof IteraplanTechnicalException) {
        LOGGER.error("Caught an unexpected exception: " + ex.getMessage(), ex);
    } else if (ex instanceof IteraplanBusinessException) {
        LOGGER.info("Handled an (expected) business exception: " + ex.getMessage(), ex);
    } else {/*from w  ww  .j av  a 2 s  .c  o m*/
        LOGGER.error("Last resort catching an unhandled Exception", ex);
    }

    IteraplanProblemReport.createFromController(ex, req);

    mav.addObject(Constants.JSP_ATTRIBUTE_EXCEPTION_MESSAGE, ex.getLocalizedMessage());
    return mav;
}

From source file:org.eclipse.jubula.client.cmd.AbstractCmdlineClient.java

/**
 * excute a job/*  ww w.ja v  a 2 s  . c om*/
 * @param args
 *      Command Line Parameter
 * @return int
 *      Exit Code
 */
public int run(String[] args) {
    Job.getJobManager().setProgressProvider(new HeadlessProgressProvider());

    ErrorMessagePresenter.setPresenter(new IErrorMessagePresenter() {
        public void showErrorMessage(JBException ex, Object[] params, String[] details) {

            log.error(ex + StringConstants.COLON + StringConstants.SPACE + ex.getMessage());
            Integer messageID = ex.getErrorId();
            showErrorMessage(messageID, params, details);
        }

        public void showErrorMessage(Integer messageID, Object[] params, String[] details) {

            Message m = MessageIDs.getMessageObject(messageID);
            if (m == null) {
                log.error(Messages.NoCorrespondingMessage + StringConstants.COLON + StringConstants.SPACE
                        + messageID);
            } else {
                String msgString = m.getMessage(params);
                if (m.getSeverity() == Message.ERROR) {
                    printlnConsoleError(msgString);
                } else {
                    printConsole(msgString);
                }
            }
        }
    });
    try {
        if (!parseCommandLine(args)) {
            return EXIT_CODE_ERROR;
        }
    } catch (ParseException e) {
        log.error(e.getLocalizedMessage(), e);
        return EXIT_CODE_ERROR;
    } catch (IOException e) {
        log.error(e.getLocalizedMessage(), e);
        return EXIT_CODE_ERROR;
    }
    preRun();
    try {
        int exitCode = doRun();

        if (isErrorOccured()) {
            exitCode = EXIT_CODE_ERROR;
        }

        printConsoleLn(Messages.ClientExitCode + exitCode, true);

        return exitCode;
    } catch (Throwable t) {
        // Assume that, if an exception has bubbled up this far, then it is 
        // a big enough problem to warrant telling the user and returning a
        // generic error exit code.
        log.error(t.getLocalizedMessage(), t);
        printlnConsoleError(t.getLocalizedMessage());
        return EXIT_CODE_ERROR;
    }
}

From source file:com.example.mego.adas.directions.ui.DirectionsFragment.java

private void fetchDirectionsData() {

    stepAdapter.clear();//from  ww  w .  ja va  2  s. co m

    if (carWayPolyLine != null) {
        carWayPolyLine.remove();
    }

    //put the start location in the firebase
    mStartLocationDatabaseReference.setValue(startLocation);

    directionsApiInterface = DirectionsApiClient.getDirectionApiClient().create(DirectionsApiInterface.class);

    Call<Direction> call = directionsApiInterface.getDirections(startLocation,
            LocationUtilities.getLatLang(goingPlace));

    call.enqueue(new Callback<Direction>() {
        @Override
        public void onResponse(Call<Direction> call, Response<Direction> response) {
            loadingbar.setVisibility(View.INVISIBLE);

            if (response.body() != null) {
                mStepsDatabaseReference.removeValue();

                Animation slideUp = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
                if (detailView.getVisibility() == View.INVISIBLE) {
                    detailView.startAnimation(slideUp);
                    detailView.setVisibility(View.VISIBLE);
                }
                if (response.body().getStatus().equals(DirectionsApiConstants.STATUES_OK)) {
                    distanceTextView.setText(DirectionsApiUtilities.getLegDistance(response.body()));
                    durationTextView.setText(DirectionsApiUtilities.getLegDuration(response.body()));
                    drawPolyline(DirectionsApiUtilities.getOverViewPolyLine(response.body()));
                    stepAdapter.setSteps(DirectionsApiUtilities.getSteps(response.body()));

                    //Put the value in the firebase
                    mStepsDatabaseReference.push().setValue(DirectionsApiUtilities.getSteps(response.body()));

                    mLegDurationTextDatabaseReference
                            .setValue(DirectionsApiUtilities.getLegDuration(response.body()));
                    mLegDistanceTextDatabaseReference
                            .setValue(DirectionsApiUtilities.getLegDistance(response.body()));
                    mOverViewPolylineDatabaseReference
                            .setValue(DirectionsApiUtilities.getOverViewPolyLine(response.body()));

                } else {
                    showToast(DirectionsApiUtilities.checkResponseState(response.body().getStatus()));
                }
            }
        }

        @Override
        public void onFailure(Call<Direction> call, Throwable t) {
            loadingbar.setVisibility(View.INVISIBLE);
            Timber.e(t.getLocalizedMessage());
        }
    });
}

From source file:de.elanev.studip.android.app.frontend.forums.ForumEntryFragment.java

@Override
protected void updateItems() {
    if (mRefreshList) {
        mRefreshList = false;/*from  ww w. ja  v a 2s  . c  o  m*/
        mOffset = 0;
    }

    if (mOffset <= 0) {
        rootEntry = new ForumEntry();
        rootEntry.subject = mSubject;
        rootEntry.content = mContent;
        rootEntry.mkdate = mDate;
        rootEntry.user = new User();
        rootEntry.user.lastname = mFullName;
        rootEntry.user.avatarNormal = mAvatar;
        mAdapter.clear();
        mAdapter.add(rootEntry);
    }
    // Return immediately when no course id is set
    if (TextUtils.isEmpty(mEntryId)) {
        return;
    }

    final ArrayList<ForumEntry> entries = new ArrayList<>();
    mCompositeSubscription.add(
            bind(mApiService.getForumTopicEntries(mEntryId, mOffset)).subscribe(new Subscriber<ForumEntry>() {
                @Override
                public void onCompleted() {

                    mAdapter.addAll(entries);
                    setRefreshing(false);
                }

                @Override
                public void onError(Throwable e) {
                    if (e instanceof TimeoutException) {
                        Toast.makeText(getActivity(), "Request timed out", Toast.LENGTH_SHORT).show();
                    } else if (e instanceof RetrofitError) {
                        Toast.makeText(getActivity(), "Retrofit error", Toast.LENGTH_LONG).show();
                    } else if (e instanceof HttpException) {
                        Toast.makeText(getActivity(), "HTTP exception", Toast.LENGTH_LONG).show();
                        Log.e(TAG, e.getLocalizedMessage());
                    } else if (e instanceof StudIpLegacyApiService.UserNotFoundException) {
                        Log.e(TAG, "User not found");
                        return;
                    } else {
                        e.printStackTrace();
                        throw new RuntimeException("See inner exception");
                    }

                    setRefreshing(false);
                }

                @Override
                public void onNext(ForumEntry entry) {
                    entries.add(entry);
                }
            }));
}