Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

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

Prototype

public Throwable(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.sonatype.siesta.webapp.test.TestResource.java

@GET
@Path("throwable")
@Produces(TEXT_PLAIN)//from ww  w.j  a  va  2s. c  om
public String throwable() throws Throwable {
    throw new Throwable("test");
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.evaluation.phrasematch.LineReader.java

@Override
public List<String> getListOfStrings(JCas jcas) throws AnalysisEngineProcessException {

    List<String> goldList = new ArrayList<String>();
    LineIterator lineIterator;/*from w w  w .  j  av a2 s .c  om*/
    try {
        lineIterator = FileUtils.lineIterator(new File(getPath(getDocumentBaseName(jcas))), encoding);
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(new Throwable(e));
    }
    try {
        while (lineIterator.hasNext()) {
            String line = lineIterator.nextLine().trim();
            if (!line.isEmpty()) {
                if (lowercase)
                    line = line.toLowerCase();
                goldList.add(line);
            }
        }
    } finally {
        LineIterator.closeQuietly(lineIterator);
    }
    return goldList;
}

From source file:io.openkit.OKHTTPClient.java

public static void putJSON(String relativeUrl, JSONObject requestParams,
        AsyncHttpResponseHandler responseHandler) {
    StringEntity sEntity = getJSONString(requestParams);
    HttpPut request = new HttpPut(getAbsoluteUrl(relativeUrl));

    if (sEntity == null) {
        responseHandler.onFailure(new Throwable("JSON encoding error"), "JSON encoding error");
    } else {//ww  w.  ja va 2  s .c o  m
        request.setEntity(sEntity);
        sign(request);
        client.put(request, "application/json", responseHandler);
    }
}

From source file:org.schedoscope.metascope.util.SchedoscopeUtil.java

private static String makeRequest(String url) throws SchedoscopeConnectException {
    Client client = Client.create();//from   w ww. j a  v  a2  s .c  o m
    WebResource webResource = client.resource(url);
    ClientResponse response = null;

    try {
        LOG.info("Execute request ...");
        long start = System.currentTimeMillis();
        response = webResource.accept("application/json").get(ClientResponse.class);
        LOG.info("Finished request in " + (System.currentTimeMillis() - start) + " ms");
    } catch (Exception e) {
        LOG.debug("Could not connect to Schedoscope instance", e);
    }

    if (response == null || response.getStatus() != 200) {
        LOG.error("Could not connect to Schedoscope REST API "
                + "(Schedoscope is not running or host/port information may be wrong)");
        throw new SchedoscopeConnectException("Could not connect to schedoscope",
                new Throwable("Could not connect"));
    }
    client.destroy();
    return response.getEntity(String.class);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.examples.io.STSReader.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    fileOffset = 0;//from w w w  .  j a v a  2s  .c o  m
    texts1 = new ArrayList<String>();
    texts2 = new ArrayList<String>();
    golds = new ArrayList<Double>();

    try {
        for (String line : FileUtils.readLines(inputFile)) {
            String parts[] = line.split("\t");

            if (parts.length != 2) {
                throw new ResourceInitializationException(new Throwable("Wrong file format: " + line));
            }

            texts1.add(parts[0]);
            texts2.add(parts[1]);
        }

        for (String line : FileUtils.readLines(goldFile)) {
            try {
                double goldValue = Double.parseDouble(line);
                golds.add(goldValue);
            } catch (NumberFormatException e) {
                throw new ResourceInitializationException(e);
            }
        }

        if (texts1.size() != golds.size()) {
            throw new ResourceInitializationException(
                    new Throwable("Size of text list does not match size of gold list."));
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}

From source file:edu.umd.cs.buildServer.util.ServletAppender.java

@Override
protected void append(LoggingEvent event) {
    if (!APPEND_TO_SUBMIT_SERVER)
        return;//  w  w  w.  j  av a2  s.  c  o  m
    try {
        Throwable throwable = null;
        if (event.getThrowableInformation() != null) {
            String[] throwableStringRep = event.getThrowableStrRep();
            StringBuffer stackTrace = new StringBuffer();
            for (String stackTraceString : throwableStringRep) {
                stackTrace.append(stackTraceString);
            }
            throwable = new Throwable(stackTrace.toString());
        }

        LoggingEvent newLoggingEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(),
                event.getLevel(), getConfig().getHostname() + ": " + event.getMessage(), throwable);

        HttpClient client = new HttpClient();
        client.setConnectionTimeout(HTTP_TIMEOUT);

        String logURL = config.getServletURL(SUBMIT_SERVER_HANDLEBUILDSERVERLOGMESSAGE_PATH);

        MultipartPostMethod post = new MultipartPostMethod(logURL);
        // add password

        ByteArrayOutputStream sink = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(sink);

        out.writeObject(newLoggingEvent);
        out.flush();
        // add serialized logging event object
        post.addPart(new FilePart("event", new ByteArrayPartSource("event.out", sink.toByteArray())));

        int status = client.executeMethod(post);
        if (status != HttpStatus.SC_OK) {
            throw new IOException("Couldn't contact server: " + status);
        }
    } catch (IOException e) {
        // TODO any way to log these without an infinite loop?
        System.err.println(e.getMessage());
        e.printStackTrace(System.err);
    }
}

From source file:com.jsonstore.database.DatabaseSchema.java

private void addSearchField(String name, SearchFieldType type) throws Throwable {
    String nameFixed;//w ww  . j av  a  2  s  .  com

    if (name == null) {
        throw new Throwable("invalid search field (null) specified");
    }

    name = name.trim();

    if (name.equals("") || (name.indexOf("..") != -1) || name.startsWith(".") || name.endsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        throw new Throwable("invalid search field (\"" + name + "\") " + "specified");
    }

    nameFixed = name.toLowerCase(Locale.ENGLISH);

    if (this.nodes.containsKey(nameFixed) || this.internalNodes.containsKey(nameFixed)) {
        throw new Throwable(
                "search field with name \"" + name + "\" " + " is used internally and cannot be reused");
    }

    this.nodes.put(nameFixed, type);
    //Used to compare what get from the user (e.g. 'x.y: string')
    //and what's inside the DB (e.g. 'x_y: TEXT')
    this.safeNodes.put(JSONStoreUtil.getDatabaseSafeSearchFieldName(nameFixed), type);
}

From source file:cz.muni.fi.sport.club.sport.club.rest.AgeGroupsResource.java

@DELETE
@Path("/{id}")
public void delete(@PathParam("id") String id) throws WebApplicationException {
    try {/*from   w w w .java2  s  . c o  m*/
        Long ids = Long.parseLong(id);
        AgeGroupDTO dto = ageGroupService.getAgeGroupById(ids);
        if (dto != null) {
            ageGroupService.deleteAgeGroup(dto);
        } else {
            throw new IllegalArgumentException();
        }
    } catch (NumberFormatException ex) {
        throw new WebApplicationException(new Throwable("You put wrong request"), Response.Status.BAD_REQUEST);
    } catch (IllegalArgumentException ex) {
        throw new WebApplicationException(new Throwable("Age Group was not found"), Response.Status.NOT_FOUND);
    } catch (Exception ex) {
        throw new WebApplicationException(new Throwable("We apologize for internal server error"),
                Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:avreye.mytarotadvisor.utils.Util.java

public static Bitmap getThumbnailfromVideoURL(String videoPath) throws Throwable {
    Bitmap bitmap = null;//from   w w w .  ja v a  2  s  .  com

    MediaMetadataRetriever mediaMetadataRetriever = null;
    try {
        mediaMetadataRetriever = new MediaMetadataRetriever();
        if (Build.VERSION.SDK_INT >= 14)
            mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
        else
            mediaMetadataRetriever.setDataSource(videoPath);
        //   mediaMetadataRetriever.setDataSource(videoPath);
        bitmap = mediaMetadataRetriever.getFrameAtTime(100);
    } catch (Exception e) {

        e.printStackTrace();
        throw new Throwable("Exception in retriveVideoFrameFromVideo(String videoPath)" + e.getMessage());

    } finally {
        if (mediaMetadataRetriever != null) {
            mediaMetadataRetriever.release();
        }
    }
    return bitmap;
}

From source file:io.github.bckfnn.reactstreams.arangodb.AsyncHttpClient.java

@Override
public <T extends Result> Stream<T> process(Operation<T> req) {
    LOG.debug("req -> " + req.getUri());
    return Stream.asOne(subscription -> {
        HttpRequest request = null;//from w w w.ja  v  a  2s  .  c o  m
        if (req.getMethod().equals("POST")) {
            HttpPost post = new HttpPost(req.getUri());
            post.setEntity(
                    new ByteArrayEntity(mapper.writeValueAsBytes(req.getBody()), ContentType.APPLICATION_JSON));
            request = post;
        } else if (req.getMethod().equals("GET")) {
            request = new HttpGet(req.getUri());
        }

        httpClient.execute(new HttpHost(host, port), request, new FutureCallback<HttpResponse>() {
            public void completed(HttpResponse result) {
                LOG.debug("res <- " + result.getStatusLine().getStatusCode());
                HttpEntity ent = result.getEntity();
                System.out.println(result.getStatusLine().getStatusCode() + " " + ent.isRepeatable());

                try {
                    T val = mapper.readValue(ent.getContent(), req.getResponseClass());
                    subscription.sendNext(val);
                    subscription.sendComplete();
                } catch (Exception e) {
                    subscription.sendError(e);
                }
            }

            public void failed(Exception ex) {
                subscription.sendError(ex);
            }

            public void cancelled() {
                subscription.sendError(new Throwable("cancelled"));
            }
        });
    });
}