Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.iisigroup.cap.report.AbstractReportHtmlService.java

@Override
public ByteArrayOutputStream generateReport(Request request) throws CapException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = null;//from   w  w  w. j  a  v a 2s.c o m
    OutputStreamWriter wr = null;
    try {
        Template t = getFmConfg().getConfiguration().getTemplate(getReportDefinition() + REPORT_SUFFIX);
        Map<String, Object> reportData = execute(request);
        wr = new OutputStreamWriter(out,
                getSysConfig().getProperty(ReportParamEnum.defaultEncoding.toString(), DEFAULT_ENCORDING));
        writer = new BufferedWriter(wr);
        t.process(reportData, writer);
    } catch (Exception e) {
        if (e.getCause() != null) {
            throw new CapException(e.getCause(), e.getClass());
        } else {
            throw new CapException(e, e.getClass());
        }
    } finally {
        IOUtils.closeQuietly(wr);
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(out);
    }
    return out;
}

From source file:ru.xxlabaza.aspect.MyAspect.java

@AfterThrowing(value = "execution(public " + // method access level
        "* " + // method return type
        "ru.xxlabaza.aspect.MyController.callMeMaybe" + // method name
        "(java.lang.String)) && args(text)", // method arguments
        argNames = "text, exception", throwing = "exception")
public void afterThrowing(String text, Exception exception) {
    log.error("\n\tERROR ->\n" + "\tIncoming argument is {}\n" + "\tException name is {}", text,
            exception.getClass().getSimpleName());
}

From source file:com.epam.ta.reportportal.commons.exception.rest.ReportPortalExceptionResolver.java

@Override
public RestError resolveError(Exception ex) {

    LOGGER.error("ReportPortalExceptionResolver > " + ex.getMessage(), ex);

    if (ReportPortalException.class.isAssignableFrom(ex.getClass())) {
        ReportPortalException currentException = (ReportPortalException) ex;
        RestError.Builder builder = new RestError.Builder();
        builder.setMessage(currentException.getMessage())
                // .setStackTrace(errors.toString())
                .setStatus(StatusCodeMapping.getHttpStatus(currentException.getErrorType(),
                        HttpStatus.INTERNAL_SERVER_ERROR))
                .setError(currentException.getErrorType());

        return builder.build();
    } else {//from   w w w .  j a v  a  2 s .  co  m
        return defaultErrorResolver.resolveError(ex);
    }
}

From source file:org.apache.cxf.fediz.service.idp.rest.RestServiceExceptionMapper.java

Response buildResponse(final Status status, final Exception ex) {
    ResponseBuilder responseBuilder = Response.status(status);
    return responseBuilder.header(APPLICATION_ERROR_CODE, ex.getClass().getName())
            .header(APPLICATION_ERROR_INFO, ex.getMessage()).status(status).build();
}

From source file:org.bibimbap.shortcutlink.RestClient.java

/**
 * Execute the REST subtasks// ww w  . ja  va2  s  .c o m
 */
protected RestClientRequest[] doInBackground(RestClientRequest... params) {
    // HttpClient that is configured with reasonable default settings and registered schemes for Android
    final AndroidHttpClient httpClient = AndroidHttpClient.newInstance(RestClient.class.getSimpleName());

    for (int index = 0; index < params.length; index++) {
        RestClientRequest rcr = params[index];
        HttpUriRequest httprequest = null;
        try {
            HttpResponse httpresponse = null;
            HttpEntity httpentity = null;

            // initiating
            publishProgress(params.length, index, RestfulState.DS_INITIATING);

            switch (rcr.getHttpRequestType()) {
            case HTTP_PUT:
                httprequest = new HttpPut(rcr.getURI());
                break;
            case HTTP_POST:
                httprequest = new HttpPost(rcr.getURI());
                break;
            case HTTP_DELETE:
                httprequest = new HttpDelete(rcr.getURI());
                break;
            case HTTP_GET:
            default:
                // default to HTTP_GET
                httprequest = new HttpGet(rcr.getURI());
                break;
            }

            // resting
            publishProgress(params.length, index, RestfulState.DS_ONGOING);

            if ((httpresponse = httpClient.execute(httprequest)) != null) {
                if ((httpentity = httpresponse.getEntity()) != null) {
                    rcr.setResponse(EntityUtils.toByteArray(httpentity));
                }
            }

            // success
            publishProgress(params.length, index, RestfulState.DS_SUCCESS);
        } catch (Exception ioe) {
            Log.i(TAG, ioe.getClass().getSimpleName());

            // clear out the response
            rcr.setResponse(null);

            // abort the request on failure
            httprequest.abort();

            // failed
            publishProgress(params.length, index, RestfulState.DS_FAILED);
        }
    }

    // close the connection
    if (httpClient != null)
        httpClient.close();

    return params;
}

From source file:de.tudarmstadt.lt.lm.app.FilterLines.java

@SuppressWarnings("static-access")
public FilterLines(String args[]) {
    Options opts = new Options();

    opts.addOption(new Option("?", "help", false, "display this message"));
    opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription(
            "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').")
            .create("f"));
    opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg()
            .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').")
            .create("o"));
    opts.addOption(OptionBuilder.withLongOpt("runparallel")
            .withDescription("Specify if processing should happen in parallel.").create("p"));
    opts.addOption(OptionBuilder.withLongOpt("maximum-perplexity").withArgName("perplexity-value").hasArg()
            .withDescription(//from   www . j a v a2  s  .  c o  m
                    "Specify the maximum perplexity value (with oov / 5th col) allowed, everything greater this value will not be printed. (default: '1000').")
            .create("m"));

    try {
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _file = cmd.getOptionValue("file", "-");
        _out = cmd.getOptionValue("out", "-");
        _parallel = cmd.hasOption("runparallel");
        _max_perp = Double.parseDouble(cmd.getOptionValue("maximum-perplexity", "1000"));

    } catch (Exception e) {
        LOG.error("{}: {}", e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, getClass().getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
}

From source file:ru.anr.base.facade.web.api.GlobalAPIExceptionHandler.java

/**
 * Processing a global exception//from  www.j  a  v  a2  s  . co m
 * 
 * @param rq
 *            Original Http request
 * @param ex
 *            An exception
 * @return String response
 * @throws Exception
 *             If rethrown
 */
@ExceptionHandler(value = { Exception.class, RuntimeException.class })
@ResponseBody
public String process(HttpServletRequest rq, Exception ex) throws Exception {

    logger.debug("API exception: {}", rq.getContextPath(), ex);

    if (AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class) != null) {
        throw ex; // Pre-defined exception handler exists
    }

    APICommand cmd = apis.error(ex);
    return cmd.getRawModel();
}

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;
        }/*  w w w  .j a v  a2  s .  c  o 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:org.opendaylight.sfc.sbrest.json.SfstExporterTest.java

@Test
// put wrong argument, illegal argument exception is expected
public void testExportJsonException() throws Exception {
    ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder();
    SfstExporter sfstExporter = new SfstExporter();

    try {//from  www .jav  a2s.c  om
        sfstExporter.exportJson(serviceFunctionForwarderBuilder.build());
    } catch (Exception exception) {
        assertEquals("Must be true", exception.getClass(), IllegalArgumentException.class);
    }

    try {
        sfstExporter.exportJsonNameOnly(serviceFunctionForwarderBuilder.build());
    } catch (Exception exception) {
        assertEquals("Must be true", exception.getClass(), IllegalArgumentException.class);
    }
}