List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.sunchenbin.store.feilong.core.lang.reflect.FieldUtil.java
/** * ???.//from w ww . j a va 2s.co m * * <pre> * {@code * example1 : * * FieldUtil.getStaticProperty("com.sunchenbin.store.feilong.core.io.ImageType", "JPG") * :jpg * } * </pre> * * @param <T> * the generic type * @param className * ??,e.g com.sunchenbin.store.feilong.core.io.ImageType * @param fieldName * ?? * @return * @see ClassUtil#loadClass(String) * @see java.lang.Class#getField(String) * @see java.lang.reflect.Field#get(Object) * * @see org.apache.commons.lang3.reflect.FieldUtils#getField(Class, String) * @since 1.4.0 */ @SuppressWarnings("unchecked") public static <T> T getStaticFieldValue(String className, String fieldName) { try { Class<?> ownerClass = ClassUtil.loadClass(className); Field field = ownerClass.getField(fieldName); return (T) field.get(ownerClass); } catch (Exception e) { String formatMessage = Slf4jUtil.formatMessage("className:[{}],fieldName:[{}]", className, fieldName); LOGGER.error(formatMessage + e.getClass().getName(), e); throw new ReflectException(formatMessage, e); } }
From source file:com.twitter.distributedlog.DLMTestUtil.java
public static <T> void validateFutureFailed(Future<T> future, Class exClass) { try {// ww w .ja v a 2 s . com Await.result(future); } catch (Exception ex) { LOG.info("Expected: {} Actual: {}", exClass.getName(), ex.getClass().getName()); assertTrue("exceptions types equal", exClass.isInstance(ex)); } }
From source file:net.malariagen.gatk.test.WalkerTest.java
/** * execute the test, given the following: * @param name the name of the test/*from w ww .ja va2s . c om*/ * @param args the argument list * @param expectedException the expected exception or null */ public static void executeTest(String name, String args, Class<?> expectedException) { CommandLineGATK instance = new CommandLineGATK(); String[] command = Utils.escapeExpressions(args); // add the logging level to each of the integration test commands // command = Utils.appendArray(command, "-et", ENABLE_REPORTING ? "STANDARD" : "NO_ET"); // run the executable boolean gotAnException = false; try { System.out.println( String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ", command))); CommandLineExecutable.start(instance, command); } catch (Exception e) { gotAnException = true; if (expectedException != null) { // we expect an exception System.out.println(String.format("Wanted exception %s, saw %s", expectedException, e.getClass())); if (expectedException.isInstance(e)) { // it's the type we expected System.out.println(String.format(" => %s PASSED", name)); } else { e.printStackTrace(); Assert.fail(String.format("Test %s expected exception %s but got %s instead", name, expectedException, e.getClass())); } } else { // we didn't expect an exception but we got one :-( throw new RuntimeException(e); } } // catch failures from the integration test if (expectedException != null) { if (!gotAnException) // we expected an exception but didn't see it Assert.fail(String.format("Test %s expected exception %s but none was thrown", name, expectedException.toString())); } else { if (CommandLineExecutable.result != 0) { throw new RuntimeException("Error running the GATK with arguments: " + args); } } }
From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java
public static Response serializeError(Exception ex) { try {//from www . j a v a 2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ex); oos.flush(); String info = new String(Base64.encodeBytesToBytes(baos.toByteArray()), MotanConstants.DEFAULT_CHARACTER); return Response.status(Status.EXPECTATION_FAILED).header(EXCEPTION_HEADER, ex.getClass()).entity(info) .build(); } catch (IOException e) { LoggerUtil.error("serialize " + ex.getClass() + " error", e); return Response.status(Status.INTERNAL_SERVER_ERROR).entity("serialization " + ex.getClass() + " error") .build(); } }
From source file:it.restrung.rest.client.DefaultRestClientImpl.java
/** * Private helper that executes an operation that may be cacheable * * @param callable the operation callable * @param apiDelegate the api delegate// w ww. j av a 2 s .c o m * @param url the url * @param user the user * @param password the password * @param timeout a request timeout * @param <T> something that extends @see JSONResponse * @return the result from executing the remote operation as a @see JSONResponse * @throws APIException */ private static <T extends JSONResponse> T executeCacheableOperation(Callable<T> callable, final APIDelegate<T> apiDelegate, final String url, final String user, final String password, final int timeout) throws APIException { RequestCache.CacheAwareOperation<T> operation = new RequestCache.CacheAwareOperation<T>(apiDelegate, callable, url, user, password, timeout); T result; try { result = operation.execute(); } catch (Exception e) { if (APIException.class.isAssignableFrom(e.getClass())) { throw (APIException) e; } else { throw new APIException(e, APIException.UNTRACKED_ERROR); } } return result; }
From source file:com.clustercontrol.infra.util.WinRMUtil.java
private static ModuleNodeResult createResultFromException(Exception e) { String message = null;/*from w ww .j a va2 s. c o m*/ if (e instanceof WsmanException) { message = getMessage((WsmanException) e); } else { message = e.getClass().getName() + ", " + e.getMessage(); } return new ModuleNodeResult(OkNgConstant.TYPE_NG, -1, message); }
From source file:com.egt.core.util.EA.java
private static void showSystemProperty(String name) { String value = System.getProperties().getProperty(name); try {/* w w w .ja v a 2s . c o m*/ Bitacora.trace(name + "=" + value); } catch (Exception ex) { Bitacora.trace(name + "=" + ex.getClass().getName()); } }
From source file:com.discovery.darchrow.bean.BeanUtil.java
/** * properties/map?bean./*w ww . j ava2 s . com*/ * * @param bean * JavaBean whose properties are being populated * @param properties * Map keyed by property name, with the corresponding (String or String[]) value(s) to be set * @see org.apache.commons.beanutils.BeanUtils#populate(Object, Map) */ public static void populate(Object bean, Map<String, ?> properties) { try { BeanUtils.populate(bean, properties); } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }
From source file:com.discovery.darchrow.bean.BeanUtil.java
/** * bean???namevalue.// w ww .ja v a 2 s . c o m * * <pre> * java.util.Date ?copy, ?? * DateConverter converter = new DateConverter(DatePattern.forToString, Locale.US); * ConvertUtils.register(converter, Date.class); * BeanUtil.copyProperty(b, a, "date"); * </pre> * * <pre> * : BeanUtils.copyProperty(a, "sample.display", "second one"); * * setProperty * * ?bean?,copyProperty()?; * setProperty()BeanUtils.populate()(??),?populate(),?override setProperty(). * ,?,setProperty()???. * * </pre> * * @param bean * bean * @param propertyName * ?Property name (can be nested/indexed/mapped/combo) * @param value * value * @see org.apache.commons.beanutils.BeanUtils#copyProperty(Object, String, Object) */ public static void copyProperty(Object bean, String propertyName, Object value) { try { BeanUtils.copyProperty(bean, propertyName, value); } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }
From source file:org.apache.usergrid.java.client.response.UsergridResponse.java
@NotNull public static UsergridResponse fromException(@Nullable final UsergridClient client, @NotNull final Exception ex) { final UsergridResponse response = new UsergridResponse(); response.client = client;// w w w . j a v a 2 s . c o m final UsergridResponseError responseError = new UsergridResponseError(); responseError.setErrorDescription(ex.getMessage()); if (ex.getClass() != null) { responseError.setErrorName(ex.getClass().toString()); } if (ex.getCause() != null) { responseError.setErrorException(ex.getCause().toString()); } response.responseError = responseError; return response; }