Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:cn.com.sinosoft.util.exception.ExceptionUtils.java

/**
 * <p>/*from w ww  .j  ava 2  s  .  com*/
 * Finds a <code>Throwable</code> by field name.
 * </p>
 * 
 * @param throwable
 *            the exception to examine
 * @param fieldName
 *            the name of the attribute to examine
 * @return the wrapped exception, or <code>null</code> if not found
 */
private static Throwable getCauseUsingFieldName(Throwable throwable, String fieldName) {
    Field field = null;
    try {
        field = throwable.getClass().getField(fieldName);
    } catch (NoSuchFieldException ignored) {
        // exception ignored
    } catch (SecurityException ignored) {
        // exception ignored
    }

    if (field != null && Throwable.class.isAssignableFrom(field.getType())) {
        try {
            return (Throwable) field.get(throwable);
        } catch (IllegalAccessException ignored) {
            // exception ignored
        } catch (IllegalArgumentException ignored) {
            // exception ignored
        }
    }
    return null;
}

From source file:cz.hobrasoft.pdfmu.operation.OperationException.java

private RpcError getRpcError() {
    RpcError re = new RpcError(getCode(), getLocalizedMessage());
    Throwable cause = getCause();
    if (cause != null || messageArguments != null) {
        re.data = new Data();
        if (cause != null) {
            re.data.causeClass = cause.getClass();
            re.data.causeMessage = cause.getLocalizedMessage();
        }//  ww  w .  j  a v  a 2  s.  c  o m
        re.data.arguments = messageArguments;
    }
    return re;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.RevokeKeySteps.java

@DomainStep("the revoke key request is received on OSGP")
public void whenTheRevokeKeyRequestIsReceivedOnOSGP() {
    LOGGER.info("WHEN: \"the revoke key request is received on OSGP\".");

    try {//  w w w  .jav  a  2  s .  co m
        this.response = this.deviceManagementEndpoint.revokeKey(ORGANISATION_ID, this.request);

    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}

From source file:com.visual_tools.nubomedia.nuboEarJava.NuboEarJavaHandler.java

private void setProcessNumberFrames(WebSocketSession session, JsonObject jsonObject) {

    try {/*from  www . j  a v a  2 s.  c  o  m*/
        int num_img = jsonObject.get("val").getAsInt();

        if (null != ear) {
            log.debug("Sending process num frames...." + num_img);

            ear.processXevery4Frames(num_img);
        }

    } catch (Throwable t) {
        error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
}

From source file:com.surevine.alfresco.repo.action.GrantEveryoneDeletePermissionsAction.java

@Override
protected synchronized void executeImpl(final Action action, final NodeRef nodeRef) {
    try {//from   w ww.  jav a 2 s  . c o  m
        if (nodeRef != null && _nodeService.exists(nodeRef)) {
            final boolean setAllow = _nodeService.getType(nodeRef).equals(ContentModel.TYPE_FOLDER);

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format("Setting delete permission to %b for %s.", setAllow, nodeRef));
            }
            synchronized (_counter) {
                _counter++;
            }
            _transactionService.getRetryingTransactionHelper()
                    .doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Boolean>() {
                        public Boolean execute() throws Throwable {
                            if (LOGGER.isDebugEnabled()) {
                                LOGGER.debug(_counter + " threads in progress");
                            }
                            try {
                                _permissionService.setPermission(nodeRef, "GROUP_EVERYONE",
                                        PermissionService.DELETE, setAllow);
                                LOGGER.debug("Permissions Set");
                            } catch (Throwable t) {
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug(
                                            "Throwable " + t.getClass() + " caught in retrying transaction");
                                }
                                throw t;
                            } finally {
                                _counter--;
                            }

                            return Boolean.TRUE;
                        }
                    }, false, true);
        }
    } catch (Exception e) { //If an exception occurs here then still allow the creation of the node and log a warning
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:io.selendroid.server.common.SelendroidResponse.java

private JSONObject buildErrorValue(Throwable e, int status, String messagePrefix) throws JSONException {
    JSONObject errorValue = new JSONObject();
    errorValue.put("class", e.getClass().getCanonicalName());

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    if (messagePrefix != null) {
        printWriter.append(messagePrefix);
    }/*from   ww w.j  av a2s  .co m*/

    // Also include the Selendroid stack trace. Only do this in case of unknown errors for easier debugging.
    // In case of an expected error the stack trace is unnecessary and users often find it confusing.
    if (status == StatusCode.UNKNOWN_ERROR.getCode()) {
        e.printStackTrace(printWriter);
    } else {
        printWriter.append(e.getMessage());
    }

    errorValue.put("message", stringWriter.toString());

    /*
      The WebDriver protocol does not define a way to add exception stack traces to responses.
      The workaround above puts the stack trace in the response message.
      Apparently Selenium's BeanToJsonConverter would also work.
            
      JSONArray stackTrace = new JSONArray();
      for (StackTraceElement el : t.getStackTrace()) {
          JSONObject frame = new JSONObject();
          frame.put("lineNumber", el.getLineNumber());
          frame.put("className", el.getClassName());
          frame.put("methodName", el.getMethodName());
          frame.put("fileName", el.getFileName());
          stackTrace.put(frame);
      }
      errorValue.put("stackTrace", stackTrace);
    */
    return errorValue;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.RevokeKeySteps.java

@DomainStep("no device should be created")
public boolean thenNoDeviceShouldBeCreated() {
    LOGGER.info("THEN: \"no device should be created\".");

    try {//from  w  w  w . j a  va  2  s. co  m
        verify(this.ssldRepositoryMock, times(0)).save(any(Ssld.class));
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }

    return true;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.RevokeKeySteps.java

@DomainStep("the revoke key request should return a revoke key response")
public boolean thenTheRequestShouldReturnAResponse() {
    LOGGER.info("THEN: \"the revoke key request should return a revoke key response\".");

    try {/*ww  w .ja  v  a2  s  .  c  o  m*/
        Assert.assertNotNull("Response should not be null", this.response);
        Assert.assertNull("Throwable should be null", this.throwable);

    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.RevokeKeySteps.java

@DomainStep("the revoke key request should return an error message")
public boolean thenTheRequestShouldReturnAnError() {
    LOGGER.info("THEN: \"the revoke key request should return an error message\".");

    try {/*from ww w .  ja va  2 s . co m*/
        Assert.assertNull("Response should be null", this.response);
        Assert.assertNotNull("Throwable should not be null", this.throwable);

    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:org.jasig.portlet.emailpreview.controller.EmailAccountSummaryController.java

@ResourceMapping(value = "accountSummary")
public ModelAndView getAccountSummary(ResourceRequest req, ResourceResponse res,
        @RequestParam("pageStart") int start, @RequestParam("numberOfMessages") int max,
        @RequestParam(value = "inboxFolder", required = false) String folder) throws IOException {

    // Define view and generate model
    Map<String, Object> model = new HashMap<String, Object>();

    String username = req.getRemoteUser();
    try {//from   www .  j  ava2 s. com

        // Force a re-load from the data source if called for by the UI.
        boolean refresh = Boolean.valueOf(req.getParameter(FORCE_REFRESH_PARAMETER));

        // Or because of a change in settings.
        if (req.getPortletSession().getAttribute(FORCE_REFRESH_PARAMETER) != null) {
            // Doesn't matter what the value is;  this calls for a refresh...
            refresh = true;
            req.getPortletSession().removeAttribute(FORCE_REFRESH_PARAMETER);
        }

        PortletPreferences prefs = req.getPreferences();

        if ((folder == null) || (folder.equals(INBOX_NAME_UNDEFINED))) {
            folder = prefs.getValue(EmailAccountSummaryController.INBOX_NAME_PREFERENCE, INBOX_NAME_DEFAULT);
        }

        String prefFolder = prefs.getValue(EmailAccountSummaryController.INBOX_NAME_PREFERENCE,
                INBOX_NAME_DEFAULT);
        if ((!prefs.isReadOnly(INBOX_NAME_PREFERENCE)) && (!folder.equals(prefFolder))) {
            prefs.setValue(INBOX_NAME_PREFERENCE, folder);
            prefs.store();
        }

        // Get current user's account information
        AccountSummary accountSummary = getEmailAccountService(req).getAccountSummary(req, start, max, refresh,
                folder);

        // Check for AuthN failure...
        if (accountSummary.isValid()) {
            model.put(KEY_ACCOUNT_SUMMARY, accountSummary);
            model.put(KEY_INBOX_URL, accountSummary.getInboxUrl());
            if (accountSummary.getQuota() == null) {
                model.put(KEY_EMAIL_QUOTA_USAGE, "-1");
            } else {
                model.put(KEY_EMAIL_QUOTA_USAGE, accountSummary.getQuota().getUsageAsPercentage());
                model.put(KEY_EMAIL_QUOTA_LIMIT, accountSummary.getQuota().getLimitAsString());
            }
        } else {
            Throwable cause = accountSummary.getErrorCause();
            if (MailAuthenticationException.class.isAssignableFrom(cause.getClass())) {
                log.info("Authentication Failure (username='" + username + "') : " + cause.getMessage());
                res.setProperty(ResourceResponse.HTTP_STATUS_CODE,
                        Integer.toString(HttpServletResponse.SC_UNAUTHORIZED));
                model.put(KEY_ERROR, "Not authorized");
            } else {
                log.error("Unanticipated Error", cause);
                res.setProperty(ResourceResponse.HTTP_STATUS_CODE,
                        Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
                model.put(KEY_ERROR, "Unanticipated Error");
            }
        }

    } catch (MailTimeoutException ex) {
        log.error("Mail Service Timeout", ex);
        res.setProperty(ResourceResponse.HTTP_STATUS_CODE,
                Integer.toString(HttpServletResponse.SC_GATEWAY_TIMEOUT));
        model.put(KEY_ERROR, "Mail Service Timeout");
    } catch (Exception ex) {
        /* ********************************************************
        In the case of an unknown error we want to send the
        exception's message back to the portlet. This will
        let implementers write specific instructions for
        their service desks to follow for specific errors.
        ******************************************************** */
        log.error("Unanticipated Error", ex);
        res.setProperty(ResourceResponse.HTTP_STATUS_CODE,
                Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
        model.put(KEY_ERROR, "ex.getMessage()");
    }

    return new ModelAndView("json", model);

}