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:org.openmrs.module.yank.api.impl.YankServiceImpl.java

@Override
public void moveYankToErrors(Yank yank, Throwable ex) {
    YankService service = Context.getService(YankService.class);

    YankError error = new YankError(yank);
    error.setDateAttempted(new Date());
    error.setAttemptedBy(Context.getAuthenticatedUser());
    error.setError(ex.getLocalizedMessage());

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    ex.printStackTrace(pw);/*from w w  w  .java2 s  . c om*/
    pw.flush();
    sw.flush();
    error.setStacktrace(OpenmrsUtil.shortenedStackTrace(sw.toString()));

    service.saveYankError(error);
    service.purgeYank(yank);
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.BuildingPolygonReader.java

public void read(final File buildingFile) throws IOException {
    LineNumberReader reader = null;
    try {/*from   ww  w .  jav  a2  s  .  c  om*/
        reader = new LineNumberReader(new FileReader(buildingFile));

        /* Ingore first line */
        if (reader.ready())
            reader.readLine();

        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            try {
                readBuildingLine(line.trim(), buildingFile);
            } catch (final NumberFormatException nfe) {
                /* A good line but bad content. Give user a hint that something might be wrong. */
                m_log.log(false,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        buildingFile.getName(), reader.getLineNumber(), nfe.getLocalizedMessage());
            } catch (final Throwable e) {
                // should never happen
                m_log.log(e,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        buildingFile.getName(), reader.getLineNumber(), e.getLocalizedMessage());
            }

        }
        reader.close();
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:com.github.leonardoxh.asyncokhttpclient.JsonAsyncHttpResponse.java

/**
 * Handle the error json message and call the onError callback
 * @param error the stack trace of error message
 * @param jsonResponse the json response to retrieve the instance
 * @see #onError(java.lang.Throwable, org.json.JSONArray)
 * @see #onError(java.lang.Throwable, org.json.JSONObject)
 *//* ww w  .j a v  a2  s.c o m*/
protected void handleErrorJsonMessage(Throwable error, Object jsonResponse) {
    if (jsonResponse instanceof JSONObject) {
        onError(error, (JSONObject) jsonResponse);
    } else if (jsonResponse instanceof JSONArray) {
        onError(error, (JSONArray) jsonResponse);
    } else if (jsonResponse == null) {
        onError(new JSONException("Null response " + error.getLocalizedMessage()), (String) null);
    } else {
        onError(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (String) null);
    }
}

From source file:tm.veriloft.mapsplayground.MapsActivity.java

private void fetchAndDrawRoute(final LatLng... latLngs) {
    final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(SERVER_PORT);

    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Loading..");
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override/*  w w  w  .j  av  a2s .  co m*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            asyncHttpClient.cancelRequests(MapsActivity.this, true);
            showCenteredToast("Drawing route got cancelled");
        }
    });

    final RequestParams requestParams = new RequestParams();

    for (LatLng latLng : latLngs) {
        requestParams.add("loc", latLng.latitude + "," + latLng.longitude);
        l("Added latLng to request, " + latLng);
    }

    asyncHttpClient.get(this, SERVER, requestParams, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            progressDialog.show();
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                ArrayList<LatLng> route = MapUtils.decodePoly(response.getString("route_geometry"));
                PolylineOptions routeOptions = new PolylineOptions();

                for (int i = 0; i < route.size(); i++) {
                    routeOptions.add(route.get(i));
                    l("Returned point " + route.get(i));
                    if (returnedPointsMarkers)
                        addedMarkers.add(mMap.addMarker(new MarkerOptions().position(route.get(i))
                                .title("#" + i + " point of #" + drawnRoutes.size())));
                }

                routeOptions.width(ROUTE_WIDTH).color(ROUTE_COLOR);
                drawnRoutes.add(mMap.addPolyline(routeOptions));

                List<LatLng> points = routeOptions.getPoints();

                if (focusAfterRouteDraw)
                    focusTo(points.get(0), 13);

                if (endMarkerRouteDraw) {
                    LatLng trueEndPoint = MapUtils.findTrueEndPoint(latLngs[latLngs.length - 1], route.get(0),
                            route.get(route.size() - 1));
                    addedMarkers.add(mMap.addMarker(
                            new MarkerOptions().position(trueEndPoint).title("End of #" + drawnRoutes.size())));
                }

                if (requestedPointMarkerRouteDraw)
                    addedMarkers.add(mMap.addMarker(new MarkerOptions().position(latLngs[latLngs.length - 1])
                            .title("Requested point of #" + drawnRoutes.size())));

            } catch (JSONException exception) {
                exception.printStackTrace();
                showCenteredToast("Exception while parsing! Error: " + exception.getLocalizedMessage());
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            showCenteredToast("Network error! Server returned non-json response, response: " + responseString
                    + ", Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFinish() {
            progressDialog.dismiss();
        }
    });
}

From source file:com.googlecode.jgenhtml.CoverageReport.java

/**
 * Write the coverage reports to the file system.
 * @param testCaseSourceFiles  The source files we are processing.
 *///from ww  w. j av  a 2 s.  c  o m
public void generateReports() throws IOException, ParserConfigurationException {
    try {
        LOGGER.log(Level.INFO, "Generating output at {0}", config.getOutRootDir().getAbsolutePath());
        Line.setTabExpand(config.getNumSpaces());
        generateCoverageReports();
        generateIndexFiles();
        generateResources();
        generateDescriptionPage();
        TopLevelIndexPage index = new TopLevelIndexPage(testTitle, indexPages);
        LOGGER.log(Level.INFO, "Writing directory view page.");
        try {

            LOGGER.log(Level.INFO, "Overall coverage rate:");
            logSummary("lines", index.getLineRate(), index.getLineHit(), index.getLineCount());
            logSummary("functions", index.getFunctionRate(), index.getFuncHit(), index.getFuncCount());
            logSummary("branches", index.getBranchRate(), index.getBranchHit(), index.getBranchCount());
        } catch (Throwable t) {
            //don't die if there is an exception in logging
            LOGGER.log(Level.WARNING, t.getLocalizedMessage());
        }
        index.writeToFileSystem();
    } catch (TransformerConfigurationException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
    } catch (TransformerException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
    }
}

From source file:com.ixora.common.ui.ShowExceptionDialog.java

/**
 * Sets the exception to show./* w  ww  .ja v  a  2  s. c o m*/
 * @param ex
 */
public void setException(Throwable ex) {
    this.exception = ex;
    this.internalError = false;
    this.requiresHtmlRenderer = false;
    String msg = ex.getLocalizedMessage();
    if (msg == null) {
        msg = ex.toString();
    }
    if (ex instanceof AppException) {
        AppException aex = (AppException) ex;
        if (aex.isInternalAppError()) {
            internalError = true;
            logger.error(aex);
            setTitle(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR));
        } else if (aex.requiresHtmlRenderer()) {
            requiresHtmlRenderer = true;
        }
    } else if (ex instanceof AppRuntimeException) {
        AppRuntimeException aex = (AppRuntimeException) ex;
        if (aex.isInternalAppError()) {
            internalError = true;
            logger.error(aex);
            setTitle(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR));
        } else if (aex.requiresHtmlRenderer()) {
            requiresHtmlRenderer = true;
        }
    }
    if (internalError || requiresHtmlRenderer) {
        // prepare the html pane
        textExceptionLong.setContentType("text/html");
        StringBuffer buff = new StringBuffer();
        buff.append("<html>");
        if (internalError) {
            buff.append(MessageRepository.get(Msg.COMMON_UI_TEXT_INTERNAL_APPLICATION_ERROR_SEND));
        }
        buff.append("<p>");
        buff.append(msg);
        buff.append("</p></html>");
        msg = buff.toString();
        setPreferredSize(largeSize);
        textExceptionLong.setText(msg);
        ((CardLayout) panel.getLayout()).show(panel, "long");
    } else if (msg.length() > 80) {
        setPreferredSize(largeSize);
        textExceptionLong.setContentType("text/plain");
        textExceptionLong.setText(msg);
        ((CardLayout) panel.getLayout()).show(panel, "long");
    } else {
        textExceptionShort.setText(msg);
        // adjust the width if the text is too long
        Dimension d = textExceptionShort.getPreferredSize();
        if (d.width > smallSize.width - 20) {
            setPreferredSize(new Dimension(d.width + 100, smallSize.height));
        } else {
            setPreferredSize(smallSize);
        }

        ((CardLayout) panel.getLayout()).show(panel, "short");
    }
    // if any other type be a little bit more verbose
    // for instance java.io.FileNotFoundException only
    // has in the message the name of the file
    // which is pretty useless so use here in the title
    // the last part of the exception's class name
    // as this is usually self explanatory
    // (this pattern is followed everywhere in
    // the jdk to avoid localization issues which is fair enough)
    // in general this situation shouldn't happen very
    // often as the basic exception should be wrapped
    // inside an AppException and given a meaningful message
    if (!(ex instanceof AppException) && !(ex instanceof AppRuntimeException)) {
        setTitle(getTitle() + " (" + getClassName(ex) + ")");
    }
}

From source file:com.poepoemyintswe.popularmovies.ui.MainFragment.java

private void getMovies() {
    MyRestAdapter.getInstance().getMovies().subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Movie>() {
                @Override/*w ww.java 2  s .c o  m*/
                public void onCompleted() {
                    mProgressWheel.setVisibility(View.GONE);
                    mRecyclerView.setVisibility(View.VISIBLE);
                }

                @Override
                public void onError(Throwable e) {
                    mProgressWheel.setVisibility(View.GONE);
                    Toast.makeText(getActivity(),
                            "Sorry! Something went wrong! Caused by " + e.getLocalizedMessage(),
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onNext(Movie movie) {
                    movieAdapter.setItems(movie.getResults());
                }
            });
}

From source file:com.poepoemyintswe.popularmovies.ui.MainFragment.java

private void getMoviesByRating() {
    MyRestAdapter.getInstance().getMoviesByRating().subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Movie>() {
                @Override//from   w  w  w . j  a  v a  2 s .  c  o m
                public void onCompleted() {
                    mProgressWheel.setVisibility(View.GONE);
                    mRecyclerView.setVisibility(View.VISIBLE);
                }

                @Override
                public void onError(Throwable e) {
                    mProgressWheel.setVisibility(View.GONE);
                    Toast.makeText(getActivity(),
                            "Sorry! Something went wrong! Caused by " + e.getLocalizedMessage(),
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onNext(Movie movie) {
                    movieAdapter.setItems(movie.getResults());
                }
            });
}

From source file:org.mc4j.ems.impl.jmx.connection.bean.attribute.DAttribute.java

/**
 * Updates the local value of this mbean from the server
 * <p/>/*from   ww  w .  j ava2 s .c o  m*/
 * TODO we should not update to null on failure, but retain the last known
 */
public synchronized Object refresh() {
    loaded = true;
    Object newValue = null;
    try {
        MBeanServer server = bean.getConnectionProvider().getMBeanServer();
        newValue = server.getAttribute(bean.getObjectName(), getName());

    } catch (ReflectionException e) {
        supportedType = false;
        registerFailure(e);
        throw new EmsException("Could not load attribute value " + e.toString(), e);
    } catch (InstanceNotFoundException e) {
        registerFailure(e);
        throw new EmsException(
                "Could not load attribute value, bean instance not found " + bean.getObjectName().toString(),
                e);
    } catch (MBeanException e) {
        registerFailure(e);
        Throwable t = e.getTargetException();
        if (t != null)
            throw new EmsException(
                    "Could not load attribute value, target bean threw exception " + t.getLocalizedMessage(),
                    t);
        else
            throw new EmsException("Could not load attribute value " + e.getLocalizedMessage(), e);
    } catch (AttributeNotFoundException e) {
        registerFailure(e);
        throw new EmsException("Could not load attribute value, attribute [" + getName() + "] not found", e);
    } catch (UndeclaredThrowableException e) {
        if (e.getUndeclaredThrowable() instanceof InvocationTargetException) {
            Throwable t = e.getCause();
            if (t.getCause() instanceof NotSerializableException) {
                supportedType = false;
                registerFailure(t.getCause());
                throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(),
                        t.getCause());
            } else
                throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(), t);
        }
        throw new EmsException("Could not load attribute value " + e.getLocalizedMessage(), e);
    } catch (RuntimeException re) {
        supportedType = false;

        // TODO GH: Figure this one out
        // Getting weblogic.management.NoAccessRuntimeException on wl9
        registerFailure(re);
        throw new EmsException("Could not load attribute value " + re.getLocalizedMessage(), re);
    } catch (NoClassDefFoundError ncdfe) {
        supportedType = false;
        registerFailure(ncdfe);
        throw new EmsException("Could not load attribute value " + ncdfe.getLocalizedMessage(), ncdfe);
    } catch (Throwable t) {
        throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(), t);
    }
    alterValue(newValue);
    return newValue;
}