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:com.siberhus.tdfl.DflBaseTest.java

@Test
public void testTemporalTypeConverter() throws Exception {
    java.sql.Date expectedDate = new java.sql.Date(
            new SimpleDateFormat("dd/MM/yyyy").parse("11/11/2011").getTime());
    java.sql.Date actualDate = (java.sql.Date) ConvertUtils.convert("11/11/2011", java.sql.Date.class);
    Assert.assertEquals(expectedDate, actualDate);
    try {//from   ww  w  .j ava 2 s  . c  o  m
        ConvertUtils.convert("invalid", java.sql.Date.class);
    } catch (Exception e) {
        Assert.assertEquals("org.apache.commons.beanutils.ConversionException", e.getClass().getName());
    }
}

From source file:com.rightscale.service.FeedScraper.java

public void run() {
    int pollPeriod = DEFAULT_POLL_PERIOD;

    while (false == _shouldStop) {
        boolean error = false;
        int interesting = 0;

        try {//w w  w.j  a v  a2  s  .  c  om
            HttpEntity response = getEntity(null, null);

            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();

            AtomParser parser = new AtomParser(this);
            xr.setContentHandler(parser);
            xr.parse(new InputSource(response.getContent()));
            response.consumeContent();
            interesting = parser.getNumInteresting();
        } catch (Exception e) {
            Log.e("FeedScraper", e.getClass().getName());
            e.printStackTrace();
            error = true;
        }

        if (error) {
            pollPeriod = ERROR_POLL_PERIOD;
        } else if (interesting == 0) {
            pollPeriod = (int) (pollPeriod * 1.5);
            pollPeriod = Math.max(pollPeriod, MAX_POLL_PERIOD);
        } else {
            pollPeriod = DEFAULT_POLL_PERIOD;
        }

        try {
            Thread.sleep(pollPeriod);
        } catch (InterruptedException e) {
            //someone may have set _shouldStop on us...
        }
    }
}

From source file:net.sf.jasperreports.engine.util.json.DefaultJsonQLExecuter.java

protected JsonQLExpression getJsonQLExpression(String expression) {
    try {//from   ww w .j av  a2  s . c o  m
        JsonQueryLexer lexer = new JsonQueryLexer(new StringReader(expression.trim()));

        JsonQueryParser parser = new JsonQueryParser(lexer);
        parser.pathExpr();

        JsonQueryWalker walker = new JsonQueryWalker();
        return walker.jsonQLExpression(parser.getAST());

    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Exception is of type: " + e.getClass());
        }
        throw new JRRuntimeException(e);
    }
}

From source file:at.ac.univie.isc.asio.jaxrs.VndErrorMapperTest.java

@Test
public void should_send_mapped_status_for_known_exceptions() throws Exception {
    final List<MediaType> noMediaTypes = Collections.emptyList();
    final ImmutableList<Exception> knownErrors = ImmutableList.<Exception>builder()
            .add(new Language.NotSupported(Language.valueOf("test"))).add(new Id.NotFound(Id.valueOf("test")))
            .add(new TypeMatchingResolver.NoMatchingFormat(noMediaTypes, noMediaTypes))
            .add(new AccessDeniedException("test")).build();
    for (final Exception failure : knownErrors) {
        final Response.Status expected = VndErrorMapper.ERROR_CODES.get(failure.getClass());
        assertThat(failure.getClass().getName() + " not mapped to expected status", subject.toResponse(failure),
                hasStatus(expected));/*  ww w  .  j  a va2s.  c  om*/
    }
}

From source file:com.adaptris.security.SingleEntryKeystoreBase.java

public void testImportCertificateChain() throws Exception {
    KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
    ksp.load();//  ww w.j  a  v  a  2 s .c  om
    try {
        ksp.importCertificateChain("", "".toCharArray(), "");
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
    try {
        ksp.importCertificateChain("", "".toCharArray(), (InputStream) null);
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
    try {
        ksp.importCertificateChain("", "".toCharArray(), (File) null);
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
}

From source file:com.adaptris.security.SingleEntryKeystoreBase.java

public void testImportPrivateKey() throws Exception {
    KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
    ksp.load();/* www.  j av a  2  s.c o  m*/
    try {
        ksp.importPrivateKey("", "".toCharArray(), "", "".toCharArray());
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
    try {
        ksp.importPrivateKey("", "".toCharArray(), (InputStream) null, "".toCharArray());
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
    try {
        ksp.importPrivateKey("", "".toCharArray(), (File) null, "".toCharArray());
        fail("Import successful");
    } catch (Exception e) {
        assertEquals(KeystoreException.class, e.getClass());
        assertTrue(e.getMessage().matches(".*is implicitly read-only.*"));
    }
}

From source file:nl.mawoo.wcmmanager.services.WCMScriptService.java

public ExecutionResult run(String content) throws ScriptException {
    ExecutionResult result = new ExecutionResult(UUID.randomUUID());
    WCMScript wcmScript = new WCMScript(result.getExecutionId(),
            new LoggingConfig(new ScriptLoggerImpl(result)));
    result.initDone();//from  ww  w  .  j  a  v a  2 s.c o m
    try {
        wcmScript.eval(content);
    } catch (Exception e) {
        String message = e.getLocalizedMessage();

        if (message == null) {
            message = e.getClass().getSimpleName();
        }

        result.setError(message);
    }
    result.executionDone();
    return result;
}

From source file:sample.fa.ScriptRunnerApplication.java

private void executeScript(ActionEvent ae) {
    ScriptEngine se = (ScriptEngine) languagesModel.getSelectedItem();
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer w = new OutputStreamWriter(baos);) {
        se.getContext().setWriter(w);/*from  w  w  w . j  a v a2s  . co  m*/

        Optional<Object> result = Optional.ofNullable(se.eval(scriptContents.getText()));

        scriptResults.setText(baos.toString() + "\n>>>>>>\n" + result.orElse("-null-").toString());
    } catch (Exception e) {
        e.printStackTrace(System.out);
        scriptResults.setText(e.getClass().getName() + " - " + e.getMessage());
    }
}

From source file:com.clustercontrol.notify.factory.ModifyNotifyRelation.java

/**
 * ????//from  w w  w  .  j  av  a2  s. com
 * <p>
 * <ol>
 *  <li>????</li>
 *  <li>???????</li>
 * </ol>
 * 
 * @param info ??
 * @return ???????<code> true </code>
 * @throws HinemosUnknown
 * 
 * @see com.clustercontrol.notify.ejb.entity.SystemNotifyInfoBean
 * @see com.clustercontrol.notify.ejb.entity.SystemNotifyEventInfoBean
 */
public boolean add(Collection<NotifyRelationInfo> info) throws HinemosUnknown {
    NotifyRelationInfo relation = null;

    try {
        if (info != null) {
            // 
            Iterator<NotifyRelationInfo> it = info.iterator();

            HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
            while (it.hasNext()) {
                relation = it.next();

                if (relation != null) {
                    em.persist(relation);
                }
            }
        }

    } catch (Exception e) {
        m_log.warn("add() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        throw new HinemosUnknown(e.getMessage(), e);
    }

    return true;
}

From source file:com.clustercontrol.notify.factory.ModifyNotifyRelation.java

/**
 * ID????//from   w w w.  ja  v a 2s .co  m
 * <p>
 * <ol>
 *  <li>ID????</li>
 * </ol>
 * 
 * @param notifyGroupId ?ID
 * @return ??????<code> true </code>
 * @throws HinemosUnknown
 */
public boolean delete(String notifyGroupId) throws HinemosUnknown {
    JpaTransactionManager jtm = new JpaTransactionManager();
    HinemosEntityManager em = jtm.getEntityManager();

    try {
        List<NotifyRelationInfo> notifies = QueryUtil.getNotifyRelationInfoByNotifyGroupId(notifyGroupId);

        Iterator<NotifyRelationInfo> it = notifies.iterator();

        while (it.hasNext()) {
            NotifyRelationInfo detail = it.next();
            em.remove(detail);
        }
        // JPA??DML??????????
        jtm.flush();
    } catch (Exception e) {
        m_log.warn("delete() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        throw new HinemosUnknown(e.getMessage(), e);
    }

    return true;
}