Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java

/**
 * @param cls the class to search the main in.
 * @param args command line args for the main class invoked.
 * @param useGUI <code>true</code> if the {@link GenericGUI} should be launched.
 * @return <code>true</code> if the class contains a <code>static main(String[])</code> that was invoked,
 *         <code>false</code> otherwise.
 * @see GenericGUI//from w ww. ja va 2s .c  o m
 */
private static boolean tryInvokeMain(Class<?> cls, String[] args, boolean useGUI) {
    try {
        if (useGUI) {
            @SuppressWarnings("unchecked")
            Class<SOMToolboxApp> sta = (Class<SOMToolboxApp>) cls;
            new GenericGUI(sta, args).setVisible(true);
            return true;
        }
    } catch (ClassCastException cce) {
        // Nop, continue...
    }

    try {
        Method main = cls.getMethod("main", String[].class);

        // special handling - if the parameter "--help" is present, also print the description
        if (ArrayUtils.contains(args, "--help")) {
            Object description = null;
            try { // try to get the LONG_DESCRIPTION field
                description = cls.getField("LONG_DESCRIPTION").get(null) + "\n";
            } catch (Exception e) {
                try { // fall back using the DESCRIPTION field
                    description = cls.getField("DESCRIPTION").get(null) + "\n";
                } catch (Exception e1) { // nothing found => write nothing...
                    description = "";
                }
            }
            System.out.println(description);
            try {
                Parameter[] options = (Parameter[]) cls.getField("OPTIONS").get(null);
                JSAP jsap = AbstractOptionFactory.registerOptions(options);
                JSAPResult jsapResult = OptionFactory.parseResults(args, jsap, cls.getName());
                AbstractOptionFactory.printUsage(jsap, cls.getName(), jsapResult, null);
                return true;
            } catch (Exception e1) { // we didn't find the options => let the class be invoked ...
            }
        }

        main.invoke(null, new Object[] { args });
        return true;
    } catch (InvocationTargetException e) {
        // If main throws an error, print it
        e.getCause().printStackTrace();
        return true;
    } catch (Exception e) {
        // Everything else is hidden...
        return false;
    }
}

From source file:cn.afterturn.easypoi.excel.export.ExcelExportService.java

protected void insertDataToSheet(Workbook workbook, ExportParams entity, List<ExcelExportEntity> entityList,
        Collection<?> dataSet, Sheet sheet) {
    try {/*www.  j  av a2s.c  o  m*/
        dataHandler = entity.getDataHandler();
        if (dataHandler != null && dataHandler.getNeedHandlerFields() != null) {
            needHandlerList = Arrays.asList(dataHandler.getNeedHandlerFields());
        }
        dictHandler = entity.getDictHandler();
        i18nHandler = entity.getI18nHandler();
        // ?
        setExcelExportStyler(
                (IExcelExportStyler) entity.getStyle().getConstructor(Workbook.class).newInstance(workbook));
        Drawing patriarch = PoiExcelGraphDataUtil.getDrawingPatriarch(sheet);
        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);
        setColumnHidden(excelParams, sheet);
        short rowHeight = entity.getHeight() != 0 ? entity.getHeight() : 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, 0)[0];
            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();
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("List data more than max ,data size is {}", dataSet.size());
        }
        // ?list Sheet
        if (dataSet.size() > 0) {
            createSheetForMap(workbook, entity, entityList, dataSet);
        } else {
            // ??
            addStatisticsRow(getExcelExportStyler().getStyles(true, null), sheet);
        }

    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause());
    }
}

From source file:com.hiperium.bo.manager.exception.ExceptionManager.java

/**
 * {@inheritDoc}/*from  w  w  w.  j  a v a2 s. c o  m*/
 */
public InformationException createMessageException(@NotNull Exception ex, @NotNull Locale locale)
        throws InformationException {
    this.log.debug("createMessageException - START");
    if (ex instanceof InformationException || ex.getCause() instanceof InformationException) {
        return (InformationException) ex;
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    InformationException informacionExcepcion = null;
    try {
        informacionExcepcion = this.findErrorCode(ex, locale);
        if (informacionExcepcion == null) {
            return InformationException.generate(EnumI18N.COMMON, EnumInformationException.SYSTEM_EXCEPTION,
                    locale);
        } else if (informacionExcepcion.getErrorCode() == null) {
            return informacionExcepcion;
        }
        ErrorLanguagePK languagePK = new ErrorLanguagePK(informacionExcepcion.getErrorCode().toString(),
                locale.getLanguage());
        ErrorLanguage errorLenguaje = this.errorLanguageDAO.findById(languagePK, false, true);
        if (errorLenguaje == null) {
            throw new NoResultException(informacionExcepcion.getMessage());
        } else {
            informacionExcepcion = new InformationException(errorLenguaje.getText());
        }
        informacionExcepcion = this.createMessageParameters(informacionExcepcion, locale);
    } catch (NoResultException e) {
        this.log.error("ERROR - MESSAGE NOT FOUND IN DATA BASE: " + e.getMessage());
    }
    this.log.debug("createMessageException - END");
    return informacionExcepcion;
}

From source file:com.nokia.carbide.installpackages.InstallPackages.java

private void getPackageList() {
    try {//from   ww  w  .ja v a2 s. co  m
        PackagesType packages = getAvailablePackagesFromServer();
        if (packages != null) {
            EList<PackageType> elist = packages.getPackage();
            packageList = new ArrayList<PackageType>(elist);
            Collections.sort(packageList, new Comparator<PackageType>() {
                public int compare(PackageType o1, PackageType o2) {
                    return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
                }
            });
            getSDKFamilyOrder(packages);
            getSDKVersionOrder(packages);
        }
    } catch (Exception e) {
        RemoteConnectionsActivator.logError(e);
        if (e.getCause() instanceof ConnectTimeoutException)
            RemoteConnectionsActivator
                    .logMessage(Messages.getString("InstallPackages.TimeoutMissingProxyMessage"), IStatus.INFO); //$NON-NLS-1$
    }
}

From source file:io.selendroid.standalone.server.grid.SelfRegisteringRemoteTest.java

@Test
public void shouldThrowMalformedURLException() {
    try {// w w  w  .  j  a v a  2 s  .c om
        givenSelfRegisteringRemote();
    } catch (Exception e) {
        assertThat("Must be instance of " + SelendroidException.class.getName(), e,
                instanceOf(SelendroidException.class));
        assertThat("Cause must be instance of " + MalformedURLException.class.getName(), e.getCause(),
                instanceOf(MalformedURLException.class));
    }
}

From source file:de.mpg.escidoc.pubman.multipleimport.processor.ZfNProcessor.java

/**
 * Fetches a file from a given URL/* ww  w. ja v a  2s .c  o m*/
 */
private InputStream fetchFile() throws Exception {
    InputStream input = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    if (!this.ftpOpen) {
        try {
            this.openFtpServer();
        } catch (Exception e) {
            this.logger.error("Could not open ftp server " + e.getCause());
            throw new Exception();
        }
    }

    if (this.f.retrieveFile(this.getCurrentFile(), out)) {
        input = new ByteArrayInputStream(out.toByteArray());
        this.fileSize = out.size();
    }

    return input;
}

From source file:com.ai.bss.webui.party.controller.PartyController.java

@RequestMapping(value = "/createLegal", method = RequestMethod.POST)
public String createLegal(@ModelAttribute("legal") @Valid Legal legal, BindingResult bindingResult,
        Model model) {/*w ww  . j  av  a  2  s .com*/
    if (!bindingResult.hasErrors()) {
        PartyId partyId = new PartyId();
        CreateLegalCommand command = new CreateLegalCommand(partyId, legal.getLegalName());
        command.setTenantId(TenantContext.getCurrentTenant());
        try {
            command = client.postForObject("http://party-service/party/createLegalCommand", command,
                    CreateLegalCommand.class);
        } catch (Exception e) {
            bindingResult.rejectValue("legalName", "error.createLegal.failed", e.getCause().getMessage());
        }
        return "redirect:/party";
    }
    return "createLegal";
}

From source file:hm.binkley.util.XProperties.java

private Object convert(final Key key) {
    final String property = key.property;
    final String wholeValue = getProperty(property);
    if (null != wholeValue)
        return wholeValue; // Literal key match wins - assume T==String
    final String[] parts = colon.split(property, 2);
    final String value = getProperty(parts[1]);
    if (null == value)
        return key.fallback;
    try {/* www  .j a  v  a 2s .  co m*/
        return converter.convert(parts[0], value);
    } catch (final Exception e) {
        throw new FailedConversionException(property, value, e.getCause());
    }
}

From source file:com.ai.bss.webui.party.controller.PartyController.java

@RequestMapping(value = "/createIndividual", method = RequestMethod.POST)
public String createIndividual(@ModelAttribute("individual") @Valid Individual individual,
        BindingResult bindingResult, Model model) {
    if (!bindingResult.hasErrors()) {
        PartyId partyId = new PartyId();
        CreateIndividualCommand command = new CreateIndividualCommand(partyId, individual.getFirstName(),
                individual.getLastName());
        command.setTenantId(TenantContext.getCurrentTenant());
        try {/*from   w w w  .  j ava2 s  .co  m*/
            command = client.postForObject("http://party-service/party/createIndividualCommand", command,
                    CreateIndividualCommand.class);
        } catch (Exception e) {
            bindingResult.rejectValue("firstName", "error.createIndividual.failed", e.getCause().getMessage());
        }
        return "redirect:/party";
    }
    return "createIndividual";
}

From source file:org.geoserver.wps.executor.DefaultProcessManager.java

@Override
public Map<String, Object> getOutput(String executionId, long timeout) throws ProcessException {
    ExecutionStatusEx status = executions.get(executionId);
    if (status == null) {
        return null;
    }//w w w  . j  a v a  2  s. c om
    try {
        if (timeout <= 0) {
            return status.future.get();
        } else {
            return status.future.get(timeout, TimeUnit.MILLISECONDS);
        }
    } catch (Exception e) {
        if (e instanceof ExecutionException && e.getCause() instanceof Exception) {
            e = (Exception) e.getCause();
        }
        if (e instanceof ProcessException) {
            throw (ProcessException) e;
        } else {
            throw new ProcessException("Process execution " + executionId + " failed", e);
        }
    } finally {
        // we're done
        executions.remove(executionId);
    }
}