List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.github.tomakehurst.wiremock.HttpsAcceptanceTest.java
private void getAndAssertUnderlyingExceptionInstanceClass(String url, Class<?> expectedClass) { boolean thrown = false; try {/*w ww . j av a 2 s . c o m*/ contentFor(url); } catch (Exception e) { Throwable cause = e.getCause(); e.printStackTrace(); if (cause != null) { assertThat(e.getCause(), instanceOf(expectedClass)); } else { assertThat(e, instanceOf(expectedClass)); } thrown = true; } assertTrue("No exception was thrown", thrown); }
From source file:cn.bzvs.excel.export.ExcelExportServer.java
public void createSheet(Workbook workbook, ExportParams entity, Class<?> pojoClass, Collection<?> dataSet) { if (workbook == null || entity == null || pojoClass == null || dataSet == null) { throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR); }/*from ww w .j a v a 2s . c o m*/ try { List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); if (entity.isAddIndex()) { excelParams.add(indexExcelEntity(entity)); } // Field fileds[] = PoiPublicUtil.getClassFields(pojoClass); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); String targetId = etarget == null ? null : etarget.value(); getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass, null); //???,?? createSheetForMap(workbook, entity, excelParams, dataSet); } catch (Exception e) { e.getMessage(); e.getMessage(); throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); } }
From source file:alfio.controller.api.admin.ResourceController.java
@ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from ww w .ja v a2 s .co m public String handleSyntaxError(Exception ex) { Optional<String> cause = Optional.ofNullable(ex.getCause()).filter(MustacheException.class::isInstance) .map(Throwable::getMessage); if (cause.isPresent()) { return cause.get(); } return "Something went wrong. Please check the syntax and retry"; }
From source file:com.mysoft.b2b.event.util.MysoftBoneCPDataSource.java
@Override public void afterPropertiesSet() throws Exception { try {/* w w w . j av a 2 s .c o m*/ if (this.pool == null) { maybeInit(); } } catch (Exception e) { logger.error("??" + e.getMessage(), e.getCause()); //???????? //???? System.exit(1); } }
From source file:it.geosolutions.geobatch.unredd.script.test.BaseTest.java
protected boolean pingGeoStore() { try {/*from ww w . jav a 2s . c o m*/ gstcu.searchLayer("_hope_there_s_no_layer_with_such_name_"); return true; } catch (Exception ex) { //... and now for an awful example of heuristic..... Throwable t = ex.getCause().getCause().getCause().getCause(); if (t instanceof ConnectException) { LOGGER.warn("Testing GeoStore is offline"); return false; } throw new RuntimeException("Unexpected exception: " + ex.getMessage(), ex); } }
From source file:com.tecapro.inventory.common.action.DelegateAction.java
/** * invoke method action for batch/*from w ww .j a v a 2 s.co m*/ * @throws Throwable */ public String execute(InfoValue info) throws Exception { long time = startLog(); String result; this.info = info; // set object info to interface readTemp.setInfo(info); writeTemp.setInfo(info); deleteTemp.setInfo(info); readUpload.setInfo(info); writeUpload.setInfo(info); deleteUpload.setInfo(info); readDownload.setInfo(info); writeDownload.setInfo(info); deleteDownload.setInfo(info); try { // invoke method action Method method = this.getClass().getMethod(actMethod, new Class[] {}); result = (String) method.invoke(this, new Object[] {}); } catch (Exception ex) { if (ex.getCause() instanceof MSException) { throw (MSException) ex.getCause(); } else { throw ex; } } endLog(time); return result; }
From source file:cn.bzvs.excel.export.ExcelExportServer.java
protected void insertDataToSheet(Workbook workbook, ExportParams entity, List<ExcelExportEntity> entityList, Collection<?> dataSet, Sheet sheet) { try {/*ww w . j av a2 s. c o m*/ dataHanlder = entity.getDataHanlder(); if (dataHanlder != null && dataHanlder.getNeedHandlerFields() != null) { needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields()); } // ? setExcelExportStyler( (IExcelExportStyler) entity.getStyle().getConstructor(Workbook.class).newInstance(workbook)); Drawing patriarch = sheet.createDrawingPatriarch(); List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); if (entity.isAddIndex()) { excelParams.add(indexExcelEntity(entity)); } excelParams.addAll(entityList); sortAllParams(excelParams); int index = entity.isCreateHeadRows() ? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; int titleHeight = index; setCellWith(excelParams, sheet); short rowHeight = getRowHeight(excelParams); setCurrentIndex(1); Iterator<?> its = dataSet.iterator(); List<Object> tempList = new ArrayList<Object>(); while (its.hasNext()) { Object t = its.next(); index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight); tempList.add(t); if (index >= MAX_NUM) break; } if (entity.getFreezeCol() != 0) { sheet.createFreezePane(entity.getFreezeCol(), 0, entity.getFreezeCol(), 0); } mergeCells(sheet, excelParams, titleHeight); its = dataSet.iterator(); for (int i = 0, le = tempList.size(); i < le; i++) { its.next(); its.remove(); } // ?list Sheet if (dataSet.size() > 0) { createSheetForMap(workbook, entity, entityList, dataSet); } else { // ?? addStatisticsRow(getExcelExportStyler().getStyles(true, null), sheet); } } catch (Exception e) { e.getMessage(); throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); } }
From source file:se.skltp.cooperation.web.rest.v1.controller.CooperationControllerTest.java
@Test public void get_shouldThrowNotFoundException() throws Exception { when(cooperationServiceMock.find(anyLong())).thenReturn(null); try {/*from w w w . j a va2 s . c o m*/ mockMvc.perform(get("/api/v1/cooperations/{id}", Long.MAX_VALUE)).andExpect(status().isNotFound()); fail("Should thrown a exception"); } catch (Exception e) { assertEquals(ResourceNotFoundException.class, e.getCause().getClass()); } }
From source file:com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadMonitor.java
private List<PartETag> collectPartETags() { final List<PartETag> partETags = new ArrayList<PartETag>(); partETags.addAll(multipartUploadCallable.getETags()); for (Future<PartETag> future : futures) { try {//from w ww. ja v a 2 s . c o m partETags.add(future.get()); } catch (Exception e) { throw new AmazonClientException("Unable to upload part: " + e.getCause().getMessage(), e.getCause()); } } return partETags; }
From source file:com.swordlord.jalapeno.DBConnection.java
public boolean persistObjectContext(ObjectContext oc) { try {//from w ww . jav a2 s .c o m oc.commitChanges(); } catch (ValidationException vex) { String strMessage = ""; ValidationResult vr = vex.getValidationResult(); if (vr.hasFailures()) { List<ValidationFailure> failures = vr.getFailures(); if (failures.size() > 0) { Iterator<ValidationFailure> it = failures.iterator(); while (it.hasNext()) { Object info = it.next(); if (info != null) { LOG.info(info); } if (info instanceof BeanValidationFailure) { BeanValidationFailure bvf = (BeanValidationFailure) info; strMessage += "- " + bvf.getDescription() + ".\n\r"; System.out.println(bvf.getSource()); } } } } String strError = "Persist crashed: " + vex.getLocalizedMessage() + ": " + vex.getCause() + "\n\r" + strMessage; LOG.info(strError); // ErrorDialog.reportError("validation: " + strMessage); return false; } catch (DeleteDenyException dde) { String strError = "Persist crashed: " + dde.getLocalizedMessage() + ": " + dde.getCause(); LOG.info(strError); // ErrorDialog.reportError(dde.getCause().getMessage()); return false; } catch (FaultFailureException ffe) { String strError = "Persist crashed: " + ffe.getLocalizedMessage() + ": " + ffe.getCause(); LOG.info(strError); // ErrorDialog.reportError(ffe.getCause().getMessage()); return false; } catch (CayenneRuntimeException cex) { String strError = "Persist crashed: " + cex.getLocalizedMessage() + ": " + cex.getCause(); LOG.info(strError); // ErrorDialog.reportError(cex.getCause().getMessage()); return false; } catch (Exception e) { String strError = "Persist crashed: " + e.getLocalizedMessage() + ": " + e.getCause(); LOG.info(strError); // ErrorDialog.reportError(e.getCause().getMessage()); return false; } return true; }