List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:edu.umn.msi.tropix.common.logging.ExceptionUtilsTest.java
@Test(groups = "unit") public void convert() { final IOException ioException = new FileNotFoundException(); final RuntimeException re = ExceptionUtils.convertException(ioException, RuntimeException.class); assert re.getCause().equals(ioException); final IllegalStateException ie = ExceptionUtils.convertException(ioException, "Moo", IllegalStateException.class); assert ie.getCause().equals(ioException) && ie.getMessage().equals("Moo"); final FileNotFoundException fe = ExceptionUtils.convertException(ioException, FileNotFoundException.class); assert fe == ioException; ExceptionUtils.ExceptionConversionException ee = null; try {/*from w w w. j a va2 s . c o m*/ ExceptionUtils.convertException(new Throwable(), NullPointerException.class); } catch (final ExceptionUtils.ExceptionConversionException iee) { ee = iee; } assert ee != null; }
From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedXMLParserTest.java
private void logOrThrowException(RuntimeException e) { if (e.getCause() instanceof java.net.ConnectException) { PubMedXMLParserTest.log.warn("Test skipped due to connection exception"); } else if (e.getCause() instanceof java.net.UnknownHostException) { PubMedXMLParserTest.log.warn("Test skipped due to unknown host exception"); } else {//w w w . jav a2 s. c o m throw (e); } }
From source file:com.denimgroup.threadfix.service.queue.scheduledjob.ScheduledRemoteProviderImporter.java
@SuppressWarnings("unchecked") public boolean addScheduledRemoteProviderImport(ScheduledRemoteProviderImport scheduledRemoteProviderImport) { String groupName = createGroupName(); String jobName = createJobName(scheduledRemoteProviderImport); JobDetail job = JobBuilder.newJob(ScheduledRemoteProviderImportJob.class).withIdentity(jobName, groupName) .build();/* w w w.j av a 2 s.co m*/ List<RemoteProviderType> remoteProviderTypes = remoteProviderTypeService.loadAll(); List<Integer> idList = (List<Integer>) CollectionUtils.collect(remoteProviderTypes, new BeanToPropertyValueTransformer("id")); String remoteProviderTypeIds = StringUtils.join(idList, ","); job.getJobDataMap().put("remoteProviderTypeIds", remoteProviderTypeIds); job.getJobDataMap().put("queueSender", queueSender); try { String cronExpression = getCronExpression(scheduledRemoteProviderImport); if (cronExpression == null) return false; Trigger trigger = TriggerBuilder.<CronTrigger>newTrigger().forJob(jobName, groupName) .withIdentity(jobName, groupName).withSchedule(cronSchedule(cronExpression)).build(); Date ft = scheduler.scheduleJob(job, trigger); log.info(job.getKey() + " has been scheduled to run at: " + ft + " and repeat based on expression: " + cronExpression); } catch (RuntimeException e) { if (e.getCause() instanceof ParseException) { log.error("Got ParseException while parsing cron expression.", e.getCause()); return false; } else { throw e; } } catch (SchedulerException scheEx) { log.error("Error when scheduling job", scheEx); return false; } return true; }
From source file:com.hortonworks.streamline.streams.storm.common.StormRestAPIClient.java
private Map doGetRequest(String requestUrl) { try {//ww w .j a v a 2 s.c om LOG.debug("GET request to Storm cluster: " + requestUrl); return Subject.doAs(subject, new PrivilegedAction<Map>() { @Override public Map run() { return JsonClientUtil.getEntity(client.target(requestUrl), STORM_REST_API_MEDIA_TYPE, Map.class); } }); } catch (RuntimeException ex) { // JsonClientUtil wraps exception, so need to compare if (ex.getCause() instanceof javax.ws.rs.ProcessingException) { if (ex.getCause().getCause() instanceof IOException) { throw new StormNotReachableException("Exception while requesting " + requestUrl, ex); } } else if (ex.getCause() instanceof WebApplicationException) { throw WrappedWebApplicationException.of((WebApplicationException) ex.getCause()); } throw ex; } }
From source file:com.sappenin.utils.appengine.tasks.aggregate.AbstractAggregatingTaskScheduler.java
@Override public TaskHandle schedule(final T payload) { try {/*from w w w .j a va 2 s.co m*/ super.schedule(payload); } catch (TaskAlreadyExistsException e) { // Do nothing - eat this exception! If the task already exists, it simply means we're aggregating // properly. getLogger().log(Level.WARNING, "Tried to schedule AggregateNotification Task with name: " + payload == null ? "unkown" : payload.getAggregatedTaskName(), e); } catch (RuntimeException re) { // Usually, the TaskAlreadyExistsException is inside of a RuntimeException if (TaskAlreadyExistsException.class.isAssignableFrom(re.getCause().getClass())) { // Do nothing - eat this exception! If the task already exists, it simply means we're aggregating // properly. getLogger().log(Level.WARNING, "Tried to schedule AggregateNotification Task with name: " + payload == null ? "unkown" : payload.getAggregatedTaskName(), re); } else { throw re; } } return null; }
From source file:com.thoughtworks.go.util.FileUtilTest.java
@Test void shouldReturnCanonicalPath() throws IOException { File f = temporaryFolder.newFolder(); assertThat(FileUtil.getCanonicalPath(f)).isEqualTo(f.getCanonicalPath()); File spyFile = spy(new File("/xyz/non-existent-file")); IOException canonicalPathException = new IOException("Failed to build the canonical path"); when(spyFile.getCanonicalPath()).thenThrow(canonicalPathException); try {// w w w .j a va2 s . c om FileUtil.getCanonicalPath(spyFile); } catch (RuntimeException e) { assertThat(e.getCause()).isEqualTo(canonicalPathException); } }
From source file:ddf.catalog.transformer.input.pptx.PptxInputTransformer.java
/** * If the slide show doesn't contain any slides, then return null. Otherwise, return jpeg * image data of the first slide in the deck. * * @param slideShow//from ww w . ja v a2s .c o m * @return jpeg thumbnail or null if thumbnail can't be created * @throws IOException */ private byte[] generatePptxThumbnail(XMLSlideShow slideShow) throws IOException { if (slideShow.getSlides().isEmpty()) { LOGGER.info("the powerpoint file does not contain any slides, skipping thumbnail generation"); return null; } Dimension pgsize = slideShow.getPageSize(); int largestDimension = (int) Math.max(pgsize.getHeight(), pgsize.getWidth()); float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension; int scaledHeight = (int) (pgsize.getHeight() * scalingFactor); int scaledWidth = (int) (pgsize.getWidth() * scalingFactor); BufferedImage img = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); try { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics.scale(scalingFactor, scalingFactor); slideShow.getSlides().get(0).draw(graphics); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { ImageIOUtil.writeImage(img, FORMAT_NAME, outputStream, RESOLUTION_DPI, IMAGE_QUALITY); return outputStream.toByteArray(); } } catch (RuntimeException e) { if (e.getCause() instanceof javax.imageio.IIOException) { LOGGER.warn("unable to generate thumbnail for PPTX file", e); } else { throw e; } } finally { graphics.dispose(); } return null; }
From source file:com.gisgraphy.webapp.action.DisplayFeatureAction.java
@Override public String execute() throws Exception { try {/*from w w w . j a v a2 s. c o m*/ if (StringUtils.isEmpty(featureId)) { errorRef = ERROR_REF_REQUIRED_FEATURE_ID; return ERROR; } if (!isNumeric(featureId)) { errorRef = ERROR_REF_NON_NUMERIC_FEATUREID; return ERROR; } FulltextQuery fulltextQuery = (FulltextQuery) new FulltextQuery( FullTextFields.FEATUREID.getValue() + ":" + featureId).withOutput(FULL_OUTPUT); FulltextResultsDto responseDTO = fullTextSearchEngine.executeQuery(fulltextQuery); List<SolrResponseDto> results = responseDTO.getResults(); int resultSize = results.size(); if (resultSize == 0) { errorRef = ERROR_REF_NORESULT; return ERROR; } else if (resultSize > 1) { errorRef = ERROR_REF_NON_UNIQUE_RESULT; return ERROR; } else { result = results.get(0); this.shape = retrieveShape(result.getFeature_id()); } } catch (RuntimeException e) { if (e.getCause() != null) { logger.warn("An error occured during search : " + e.getCause().getMessage()); } else { logger.warn("An error occured during search : " + e.getMessage()); } this.errorRef = ERROR_REF_GENERAL_ERROR; this.errorMessage = e.getMessage(); return ERROR; } return SUCCESS; }
From source file:com.nesscomputing.log.jmx.Log4JMBean.java
private void exportMBean(final String name, final Object bean) { synchronized (exportedObjects) { try {// w w w.ja va2s. c o m exporter.export(name, bean); exportedObjects.put(bean, name); } catch (RuntimeException re) { if (re.getCause() instanceof InstanceAlreadyExistsException) { LOG.warn("Could not export '%s', already exists!", name); } else { throw re; } } } }
From source file:uniol.synthesis.expansion.RealiseFormulaTest.java
@Test public void testImpossibleException() { // Prepare a transition system which causes a MissingLocationException. This can not happen in the // actual algorithm since nothing adds locations there. TransitionSystem ts = new TransitionSystem(); ts.createStates("s0", "s1"); ts.setInitialState("s0"); ts.createArc("s0", "s1", "a"); ts.createArc("s0", "s1", "b"); ts.getEvent("a").putExtension("location", "a"); try {/*from ww w . j a v a 2s . co m*/ new RealiseFormula.DefaultOverapproximateTS(new PNProperties()).overapproximate(ts); fail(); } catch (RuntimeException e) { assertThat(e.getCause(), instanceOf(MissingLocationException.class)); } }