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:com.solace.samples.cloudfoundry.securesession.controller.SolaceController.java

/**
 * This formats a string showing the exception class name and message, as
 * well as the class name and message of the underlying cause if it exists.
 * Then it returns that string in a ResponseEntity.
 * /*w  w  w . j  ava 2s .  c o  m*/
 * @param exception
 * @return ResponseEntity<String>
 */
private ResponseEntity<String> handleError(Exception exception) {

    Throwable cause = exception.getCause();
    String causeString = "";

    if (cause != null) {
        causeString = "Cause: " + cause.getClass() + ": " + cause.getMessage();
    }

    String desc = String.format("{'description': ' %s: %s %s'}", exception.getClass().toString(),
            exception.getMessage(), causeString);
    return new ResponseEntity<>(desc, HttpStatus.BAD_REQUEST);

}

From source file:com.scistor.queryrouter.server.impl.JdbcHandlerImpl.java

/**
 * sql??//  www .  j  a v a2  s .  c  o m
 *
 * @return List<Map<String, Object>> formd tableresult data
 */
public List<Map<String, Object>> queryForList(String sql) {
    long begin = System.currentTimeMillis();
    List<Map<String, Object>> result = null;
    try {
        result = jdbcTemplate.queryForList(sql);
    } catch (Exception e) {
        logger.error("queryId:{} select sql error:{}", 1, e.getCause().getMessage());
        throw e;
    } finally {
        logger.info("queryId:{} select sql cost:{} ms resultsize:{}", 1, System.currentTimeMillis() - begin,
                result == null ? null : result.size());
    }
    return result;
}

From source file:net.jkratz.igdb.controller.advice.ErrorController.java

@RequestMapping(produces = "application/json")
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody Map<String, Object> handleUncaughtException(Exception ex) {
    logger.error("Unhandled Exception", ex);
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Generic Error");
    map.put("message", ex.getMessage());
    if (ex.getCause() != null) {
        map.put("cause", ex.getCause().getMessage());
    }//from  w  ww . ja  v a 2 s. c  om
    return map;
}

From source file:io.lavagna.web.helper.GeneralHandlerExceptionResolver.java

private void handleException(Exception ex, HttpServletResponse response) {
    for (Entry<Class<? extends Throwable>, Integer> entry : statusCodeResolver.entrySet()) {
        if (ex.getClass().equals(entry.getKey())) {
            response.setStatus(entry.getValue());
            LOG.info("Class: {} - Message: {} - Cause: {}", ex.getClass(), ex.getMessage(), ex.getCause());
            LOG.info("Cnt", ex);
            return;
        }/*www.ja v  a  2s.co m*/
    }
    /**
     * Non managed exceptions flow Set HTTP status 500 and log the exception with a production visible level
     */
    response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    LOG.warn(ex.getMessage(), ex);
}

From source file:com.scistor.queryrouter.server.impl.JdbcHandlerImpl.java

/**
 * queryForInt/*from   w w w.j a va  2  s. c  o m*/
 * 
 * @param sql
 *            sql
 * @param whereValues
 *            whereValues
 * @return int count
 */
public int queryForInt(String sql, List<Object> whereValues) {
    long begin = System.currentTimeMillis();
    Map<String, Object> result = null;
    int count = 0;
    try {
        logger.info("queryId:{} count sql: {}", 1, this.toPrintString(sql, whereValues));
        result = this.jdbcTemplate.queryForMap(sql, whereValues.toArray());
        count = Integer.valueOf(result.values().toArray()[0].toString()).intValue();
    } catch (Exception e) {
        logger.error("queryId:{} select sql error:{}", 1, e.getCause().getMessage());
        throw e;
    } finally {
        logger.info("queryId:{} select count sql cost:{} ms, result: {}", 1, System.currentTimeMillis() - begin,
                count);
    }
    return count;
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.AndroidOperations.java

/**
 * Creates the mobile instance.//from w  w  w .  j  a v a2 s .  c  o m
 * @param deviceType the device type
 * @return the web driver
 * @throws DeviceException the device exception
 */
private WebDriver createMobileInstance(final boolean deviceType) throws DeviceException {

    if (!hasErrors) {
        try {
            setLogString(LogSection.START, deviceType ? "Uninstalling App" : "Installing App", true);
            final File app = getAppPath();
            setLogString("App Location : " + app.getPath(), true);
            final DesiredCapabilities capabilities = setDriverCapabilities(deviceType, app);
            setLogString("Launch webdriver", true);
            final WebDriver driver = new SwipeableWebDriver(new URL(getAppiumHostUrl()), capabilities);
            setLogString(LogSection.END, "App Process Completed", true);
            return driver;
        } catch (Exception ex) {
            if (ex.getCause() instanceof HttpHostConnectException) {
                setErrorMsg("\033[41;1mAppium not started, Please start.");
                setLogString(LogSection.END, errorMsg, true);
                hasErrors = true;
                throw new DeviceException(getErrorMsg());
            }
            logInitializationError(ex);
        }
    }
    return null;
}

From source file:eu.seaclouds.platform.planner.core.Planner.java

private Map<String, Pair<NodeTemplate, String>> parseOfferings(String offerings) {
    Map<String, Pair<NodeTemplate, String>> map = new HashMap<>();
    try {/*from   www.j a  va2s. co m*/
        ParsingResult<ArchiveRoot> offeringRes = ToscaSerializer.fromTOSCA(offerings);
        Map<String, NodeTemplate> offering = offeringRes.getResult().getTopology().getNodeTemplates();
        Yaml yml = new Yaml();
        Map<String, Map<String, Object>> adpYaml = (Map<String, Map<String, Object>>) yml.load(offerings);
        Map<String, Object> nodeTemplates = (Map<String, Object>) adpYaml.get("topology_template")
                .get("node_templates");

        for (String node : offering.keySet()) {

            Map<String, Object> properties = ((Map<String, Map<String, Object>>) nodeTemplates.get(node))
                    .get("properties");
            String location = (String) properties.get("location");

            if (deployableProviders == null || deployableProviders.contains(location)) {

                NodeTemplate nt = offering.get(node);
                HashMap<String, Object> offerMap = new HashMap<>();
                offerMap.put(node, nodeTemplates.get(node));
                String offerDump = yml.dump(offerMap);

                map.put(node, new Pair<NodeTemplate, String>(nt, offerDump));
            }
        }
    } catch (Exception e) {
        log.error(e.getCause().getMessage());
    }

    return map;
}

From source file:com.adito.navigation.ExceptionHandler.java

public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance,
        HttpServletRequest request, HttpServletResponse response) throws ServletException {
    log.error("An error occured during action processing. ", ex);
    if (ex instanceof PopupException) {
        request.getSession().setAttribute(Constants.EXCEPTION, ex.getCause());
        return mapping.findForward("popupException");
    } else {/*from   www.  ja  v  a  2  s.c o  m*/
        request.getSession().setAttribute(Constants.EXCEPTION, ex);
        return mapping.findForward("exception");
    }
}

From source file:com.scistor.queryrouter.server.impl.JdbcHandlerImpl.java

/**
 * sql??//from w w w .j  a  va 2 s.  c om
 * 
 * @return List<Map<String, Object>> formd tableresult data
 */
public List<Map<String, Object>> queryForList(String sql, List<Object> whereValues) {
    long begin = System.currentTimeMillis();
    List<Map<String, Object>> result = null;
    try {
        logger.info("queryId:{} sql: {}", 1, this.toPrintString(sql, whereValues));
        if (null == whereValues) {
            result = jdbcTemplate.queryForList(sql);
        } else {
            result = this.jdbcTemplate.queryForList(sql, whereValues.toArray());
        }
    } catch (Exception e) {
        logger.error("queryId:{} select sql error:{}", 1, e.getCause().getMessage());
        throw e;
    } finally {
        logger.info("queryId:{} select sql cost:{} ms resultsize:{}", 1, System.currentTimeMillis() - begin,
                result == null ? null : result.size());
    }
    return result;
}

From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.wizards.migration.ModelMigrationWizard.java

@Override
public boolean performFinish() {
    System.out.println("ModelMigrationWizard.performFinish()");
    final GeneralProjectMigration page = (GeneralProjectMigration) getContainer().getCurrentPage();
    final String libraryId = page.getFieldValueString(GeneralProjectMigration.Fields.library.toString());
    // import library if project do not exists in workspace

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                execute(page, libraryId, monitor);
            } catch (Exception e) {

                throw new InvocationTargetException(e);
            }//ww w.  j  a v a  2 s .  c o m
        }
    };

    try {
        this.getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        Activator.getDefault().getLog()
                .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, cause.toString(), cause));
        MessageDialog.openError(getShell(), "Error", NLS.bind("Internal error {0}", cause.getMessage())); //$NON-NLS-1$
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;
}