Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ca.uhn.hl7v2.model.tests.GenericPrimitiveTest.java

License:asdf

/**
 * Testing set/getValue() with various date strings
 *///from   w ww.  ja v  a  2s .  co  m
@Test
public void testSetGetValue() throws DataTypeException {
    class TestSpec {
        String value;
        Object outcome;
        Exception exception = null;

        TestSpec(String value, Object outcome) {
            this.value = value;
            this.outcome = outcome;
        }

        public String toString() {
            return "[ " + value + " : " + (outcome != null ? outcome : "null")
                    + (exception != null ? " [ " + exception.toString() + " ]" : " ]");
        }

        public boolean executeTest() {
            GenericPrimitive gp = new GenericPrimitive(message);
            try {
                gp.setValue(value);
                String retval = gp.getValue();
                if (retval != null) {
                    return retval.equals(outcome);
                } else {
                    return outcome == null;
                }
            } catch (Exception e) {
                if (e.getClass().equals(outcome)) {
                    return true;
                } else {
                    this.exception = e;
                    return (e.getClass().equals(outcome));
                }
            }
        }
    }//inner class

    TestSpec[] tests = { new TestSpec(null, null), new TestSpec("", ""), new TestSpec(" ", " "),
            new TestSpec("abcdefghijklmnopqrstuv", "abcdefghijklmnopqrstuv"),
            new TestSpec("1234aBCDerfgkyuy^asdflkasd|adsjkl", "1234aBCDerfgkyuy^asdflkasd|adsjkl"),
            new TestSpec(" ", " "), new TestSpec("", ""), new TestSpec(null, null), };

    ArrayList failedTests = new ArrayList();

    for (int i = 0; i < tests.length; i++) {
        if (!tests[i].executeTest())
            failedTests.add(tests[i]);
    }

    assertEquals("Failures: " + failedTests, 0, failedTests.size());
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.property.SimplePropertyCloner.java

@Override
protected <T> boolean cloneValue(Object source, Object target, String propertyName, Object propertyValue,
        HibernateEntityGraphCloner entityGraphCloner) throws IllegalArgumentException {

    // null properties are always be treated as simple
    if ((propertyValue == null) || propertyClassifier.isSimpleProperty(propertyValue.getClass())) {

        try {/*from   w  w w.  j  a  va  2  s. c  o m*/
            PropertyUtils.setSimpleProperty(target, propertyName, propertyValue);
            return true;
        } catch (Exception exception) {
            throw new IllegalArgumentException("Unable to set property '" + propertyName + "' on " + target
                    + " due to " + exception.getClass().getSimpleName() + ": " + exception.getMessage());
        }

    }

    // other properties can't be handled by this cloner
    return false;
}

From source file:br.com.mv.modulo.web.ExceptionController.java

@ExceptionHandler(Exception.class)
@RequestMapping("/exception")
public ModelAndView handleException(HttpServletRequest req, Exception e) throws Exception {
    log.trace("Exceo capturada:", e);
    e.printStackTrace();//from  w ww  .j a  v a 2s  .c  o m
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    ModelAndView mav = new ModelAndView("exception");
    mav.addObject("exception", e);
    exception = e;

    mav.addObject("timestamp", new Date());
    mav.addObject("url", req.getRequestURL());
    mav.addObject("status", 500);
    return mav;
}

From source file:com.bt.aloha.fitnesse.InboundConferenceFixture.java

public String createDialog() {
    try {/*www  . j a  v  a  2  s .co  m*/
        switch (activeParticipant) {
        case 1:
            firstDialogId = conferenceBean.createParticipantCallLeg(conferenceId, URI.create(firstPhoneUri));
            break;
        case 2:
            secondDialogId = conferenceBean.createParticipantCallLeg(conferenceId, URI.create(secondPhoneUri));
            break;
        case 3:
            thirdDialogId = conferenceBean.createParticipantCallLeg(conferenceId, URI.create(thirdPhoneUri));
            break;
        }
        return "OK";
    } catch (Exception e) {
        return "Exception:" + e.getClass().getSimpleName();
    }
}

From source file:com.acc.controller.VouchersController.java

/**
 * Handles Vouchers controller specific exceptions
 * /*from w  w  w.jav  a2 s  .  c o m*/
 * @param excp
 *           to support basic exception marshaling to JSON and XML. It will determine the format based on the
 *           request's Accept header.
 * @param request
 * @param writer
 * @throws java.io.IOException
 * 
 * @return {@link com.acc.error.data.ErrorData} as a response body
 */
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
@ExceptionHandler({ VoucherOperationException.class })
public ErrorData handleCartException(final Exception excp, final HttpServletRequest request,
        final Writer writer) throws IOException {
    LOG.info("Handling Exception for this request - " + excp.getClass().getSimpleName() + " - "
            + excp.getMessage());
    if (LOG.isDebugEnabled()) {
        LOG.debug(excp);
    }
    final ErrorData errorData = handleErrorInternal(excp.getClass().getSimpleName(), excp.getMessage());
    return errorData;
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.property.CloneablePropertyCloner.java

@Override
protected <T> boolean cloneNonNullValue(Object source, Object target, String propertyName, Object propertyValue,
        HibernateEntityGraphCloner entityGraphCloner) throws IllegalArgumentException {

    if (propertyValue instanceof Cloneable) {

        try {/* w  ww  .j a va2  s  . co m*/
            PropertyUtils.setSimpleProperty(target, propertyName, clone((Cloneable) propertyValue));
            return true;
        } catch (Exception exception) {
            throw new IllegalArgumentException("Unable to set property '" + propertyName + "' on " + target
                    + " due to " + exception.getClass().getSimpleName() + ": " + exception.getMessage());
        }

    }

    // other properties can't be handled by this cloner
    return false;
}

From source file:com.netflix.genie.web.controllers.GenieExceptionMapper.java

private void countException(final Exception e) {
    Id taggedId = this.exceptionCounterId.withTag(MetricsConstants.TagKeys.EXCEPTION_CLASS,
            e.getClass().getCanonicalName());

    if (e instanceof GenieUserLimitExceededException) {
        final GenieUserLimitExceededException userLimitExceededException = (GenieUserLimitExceededException) e;
        taggedId = taggedId.withTag("user", userLimitExceededException.getUser()).withTag("limit",
                userLimitExceededException.getExceededLimitName());
    }/*from www  .j  a  v  a  2 s  . c om*/

    this.registry.counter(taggedId).increment();
}

From source file:org.thingsplode.agent.monitors.providers.SystemComponentProvider.java

private void logAndSendError(Exception ex) {
    String e = String.format("%s error caught while reading networks states with message: %s",
            ex.getClass().getSimpleName(), ex.getMessage());
    logger.error(e, ex);//  w w  w  .  jav  a2  s .  com
    eventQueueManager.sendFaultEvent(Event.Severity.WARNING, e);
}

From source file:com.hundsun.sso.controller.OAuthRestController.java

@ExceptionHandler(Exception.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
    LOG.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
    return getExceptionTranslator().translate(e);
}

From source file:com.hundsun.sso.controller.OAuthRestController.java

@ExceptionHandler(ClientRegistrationException.class)
public ResponseEntity<OAuth2Exception> handleClientRegistrationException(Exception e) throws Exception {
    LOG.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
    return getExceptionTranslator().translate(new BadClientCredentialsException());
}