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.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * Moved from ASSIGN here /* w ww. j  a va 2 s  .c om*/
 */
@Override
Node fetchVariableData(VariableInstance variable, boolean forWriting) throws FaultException {
    try {
        return super.fetchVariableData(variable, forWriting);
    } catch (FaultException fe) {
        if (forWriting) {
            fe = new FaultException(fe.getQName(), fe.getMessage(),
                    new Throwable("throwUninitializedToVariable"));
        }
        throw fe;
    }
}

From source file:mobisocial.musubi.ui.ViewProfileActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_tabbed);

    Intent intent = getIntent();//from  w w w  . j ava  2s  .c o  m

    Long id = null;
    // intent from address book
    Intent is = getIntent();
    Uri data = getIntent().getData();
    String type = getIntent().getType();
    if (data != null) {
        if (type != null && type.equals(MusubiContentProvider.getType(Provided.IDENTITIES_ID))) {
            id = ContentUris.parseId(data);
        } else if (data.getAuthority().equals(ContactsContract.AUTHORITY)) {
            // intent sent from address book have null type
            long rawId = ContentUris.parseId(data);
            id = getMusubiId(rawId);
        }
    }
    if (id == null) {
        id = intent.getLongExtra(PROFILE_ID, -1);
    }

    setTitle("Relationships");
    mLabels.add("Profile");
    mFragments.add(ViewProfileFragment.newInstance(id));

    SQLiteOpenHelper helper = App.getDatabaseSource(this);
    IdentitiesManager im = new IdentitiesManager(helper);
    MIdentity identity = im.getIdentityForId(id);
    if (identity == null) {
        UsageMetrics.getUsageMetrics(this)
                .report(new Throwable("Invalid identity " + id + " passed tp ViewProfileActivity"));
        finish();
        return;
    }

    FeedManager fm = new FeedManager(helper);
    mFeedIds = fm.getFeedsForIdentityId(id);

    setTitle(identity.name_);

    if (!identity.owned_) {
        mLabels.add("Conversations");
        Bundle args = new Bundle();
        args.putLong(ConversationsFragment.ARG_IDENTITY_ID, identity.id_);
        ConversationsFragment f = new ConversationsFragment();
        f.setArguments(args);
        mFragments.add(f);
    } else {
        setTitle("Your profile");
    }

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments, mLabels);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);

    //Bind the tab indicator to the adapter
    TabPageIndicator tabIndicator = (TabPageIndicator) findViewById(R.id.feed_titles);
    tabIndicator.setViewPager(mViewPager);
}

From source file:sh.calaba.driver.model.CalabashAndroidDriver.java

public WebDriverLikeResponse execute(WebDriverLikeRequest request) throws Exception {
    HttpClient client = HttpClientFactory.getClient();

    String url = remoteURL + request.getPath();
    BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(request.getMethod(), url);
    if (request.hasPayload()) {
        r.setEntity(new StringEntity(request.getPayload().toString(), "UTF-8"));
    }/*  www  .j  a  va  2s .c  o  m*/

    HttpHost h = new HttpHost(host, port);

    HttpResponse response = client.execute(h, r);
    if (response.getStatusLine().getStatusCode() == 500) {
        throw new CalabashException(
                "The Server responded with a server error. Is the Calabash-driver-server started?",
                new Throwable(response.toString()));
    }

    JSONObject o = Helper.extractObject(response);
    if (o == null) {
        return new FailedWebDriverLikeResponse(null,
                new SessionNotCreatedException("An error occured while creating a new session"));
    }
    return new WebDriverLikeResponse(o);
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.KeyphraseWriter.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    StringBuilder sb = new StringBuilder();
    sb.append("Lowercase: ");
    sb.append(lowercase);/* ww  w .ja v a  2  s .c om*/
    sb.append(LF);
    sb.append("Remove fully contained keyphrases: ");
    sb.append(removeContained);
    sb.append(LF);
    sb.append(LF);
    if (writeToFile && fileName == null) {
        throw new ResourceInitializationException(new Throwable("File name should be defined."
                + "Please assign a file name to the configuration parameter PARAM_FILE_NAME."));
    }
    getContext().getLogger().log(Level.INFO, sb.toString());
}

From source file:dkpro.similarity.experiments.wordpairs.io.WordPairReader.java

/**
 * Processes a text containing a word pair list.
 * Expected format of the list:/*from  w ww.  j  ava2 s . co  m*/
 *   - each pair on a single line
 *   - words separated by a the value indicated by the separator parameter (default ":"), e.g. 'car:automobile'
 *   - followed by the gold standard value and two pos tags from the set (n,v,a)
 *   - everything starting with the value indicated by the comment parameter (default "#") is ignored
 * @param cas The CAS.
 * @param document The document text to process.
 * @throws AnalysisEngineProcessException
 */
private void processDocument(JCas jcas, String document) throws CollectionException {

    // split document into lines
    String[] lines = document.split(LINE_SEP);

    int i = 0;
    int startOffset = 0;
    for (String line : lines) {
        i++;

        if (line.startsWith(commentChar)) {
            startOffset += line.length() + LINE_SEP.length();
            continue;
        }

        String[] parts = line.split(separatorChar);
        if (parts.length < 2 || parts.length > 5) {
            this.getLogger().log(Level.SEVERE, "Wrong file format:  " + line);
            throw new CollectionException(new Throwable("Wrong file format on line '" + i + " " + line
                    + "'. It should be word1:word2:gold[:pos1:pos2]"));
        }

        Token token1 = new Token(jcas);
        token1.setBegin(startOffset);
        token1.setEnd((startOffset + parts[0].length()));
        token1.addToIndexes();

        Token token2 = new Token(jcas);
        token2.setBegin(startOffset + parts[0].length() + 1);
        token2.setEnd(startOffset + parts[0].length() + 1 + parts[1].length());
        token2.addToIndexes();

        String goldValueString = parts[2];
        double goldValue = -1.0;
        try {
            goldValue = new Double(goldValueString);
        } catch (NumberFormatException e) {
            this.getLogger().log(Level.INFO, "Wrong number format: " + goldValueString);
            startOffset += line.length() + LINE_SEP.length();
            continue;
        }

        POS pos1 = new POS(jcas, token1.getBegin(), token1.getEnd());
        pos1.setPosValue(parts[3]);
        pos1.addToIndexes();

        POS pos2 = new POS(jcas, token2.getBegin(), token2.getEnd());
        pos2.setPosValue(StringUtils.chomp(parts[4]));
        pos2.addToIndexes();

        SemRelWordPair wordPairAnnotation = new SemRelWordPair(jcas);
        wordPairAnnotation.setBegin(token1.getBegin());
        wordPairAnnotation.setEnd(token2.getEnd());
        wordPairAnnotation.setWord1(token1.getCoveredText());
        wordPairAnnotation.setWord2(token2.getCoveredText());
        wordPairAnnotation.setToken1(token1);
        wordPairAnnotation.setToken2(token2);
        wordPairAnnotation.setPos1(pos1);
        wordPairAnnotation.setPos2(pos2);
        wordPairAnnotation.setGoldValue(goldValue);

        wordPairAnnotation.addToIndexes();

        startOffset += line.length() + LINE_SEP.length();
    }
}

From source file:de.unidue.ltl.integration.mekaMultiLabel.MultiLabelOutcomeAnnotator.java

public Set<String> getTextClassificationOutcomes(JCas jcas) throws CollectionException {
    Set<String> outcomes = new HashSet<String>();

    DocumentMetaData dmd = DocumentMetaData.get(jcas);
    String titleWithoutExtension = FilenameUtils.removeExtension(dmd.getDocumentTitle());

    if (!goldLabelMap.containsKey(titleWithoutExtension)) {
        throw new CollectionException(new Throwable("No gold label for document: " + dmd.getDocumentTitle()));
    }//from   www  .  ja  v  a  2  s .c om

    for (String label : goldLabelMap.get(titleWithoutExtension)) {
        outcomes.add(label);
    }
    return outcomes;
}

From source file:net.officefloor.plugin.socket.server.http.integrate.HttpCleanupServerTest.java

/**
 * Ensure report cleanup {@link Escalation}.
 */// ww  w  .  j  a  v  a  2  s  . co m
public void testCleanupEscalation() throws Exception {

    // Specify the escalations
    final Throwable escalation = new Throwable("TEST");
    RecycleEscalationManagedObjectSource.escalation = escalation;

    // Undertake request
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {

        // Create the request
        HttpGet method = new HttpGet(this.getServerUrl() + "/path");

        // Obtain the response (should be server error)
        HttpResponse response = client.execute(method);
        int status = response.getStatusLine().getStatusCode();
        assertEquals("Incorrect status", 500, status);

        // Read in the body of the response
        String responseEntity = HttpTestUtil.getEntityBody(response);
        StringWriter expectedEntity = new StringWriter();
        expectedEntity.write("Cleanup of object type " + RecycleEscalationManagedObjectSource.class.getName()
                + ": TEST (" + escalation.getClass().getSimpleName() + ")\n");
        assertEquals("Incorrect response entity", expectedEntity.toString(), responseEntity);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.jwpl.WikipediaRevisionPairReader.java

@Override
public void getNext(JCas jcas) throws IOException, CollectionException {
    super.getNext(jcas);

    Timestamp currentTimestamp = timestampIter.next();

    if (currentTimestamp == null) {
        throw new CollectionException(new Throwable("Current timestamp is null. Upps ... should not happen."));
    }//from w  ww .j  a  v a 2  s  . com

    this.getLogger().log(Level.FINE, currentArticle.getPageId() + "-" + currentTimestamp);

    try {

        JCas revView1 = jcas.createView(REVISION_1);
        JCas revView2 = jcas.createView(REVISION_2);

        Revision revision1;
        Revision revision2;
        String text1 = "";
        String text2 = "";

        if (nrOfRevisionsProcessed < skipFirstNPairs) {
            if (nrOfRevisionsProcessed % 1000 == 0) {
                this.getLogger().log(Level.INFO, "Skipping " + nrOfRevisionsProcessed + "th revision.");
            }
            // create fake revisions
            revision1 = getRevision(null);
            revision2 = getRevision(null);
        } else {
            revision1 = getRevision(savedTimestamp);
            revision2 = getRevision(currentTimestamp);

            text1 = getText(revision1);
            text2 = getText(revision2);

            int difference = Math.abs(text1.length() - text2.length());
            if (difference < minChange || difference > maxChange) {
                text1 = "";
                text2 = "";
            }
        }

        revView1.setDocumentText(text1);
        revView2.setDocumentText(text2);

        addDocumentMetaData(jcas, currentArticle.getPageId(), revision1.getRevisionID());
        addDocumentMetaData(revView1, currentArticle.getPageId(), revision1.getRevisionID());
        addDocumentMetaData(revView2, currentArticle.getPageId(), revision2.getRevisionID());

        addRevisionAnnotation(revView1, revision1);
        addRevisionAnnotation(revView2, revision2);

        savedTimestamp = currentTimestamp;

        if (!timestampIter.hasNext()) {
            savedTimestamp = null;
        }

        nrOfRevisionsProcessed++;
    } catch (WikiApiException e) {
        throw new CollectionException(e);
    } catch (CASException e) {
        throw new CollectionException(e);
    }
}

From source file:info.novatec.testit.livingdoc.runner.CommandLineRunnerTest.java

@Test
public void testThatDebugModeAllowToSeeWholeStackTrace() throws Exception {

    String input = getResourcePath("/specs/ABankSample.html");
    File outputFile = outputFile("report.html");

    CommandLineRunner commandLineRunner = new CommandLineRunner();
    commandLineRunner.run("--debug", input, outputFile.getAbsolutePath());

    try {//from  ww w  . ja v  a2s .  c o  m
        throw new Exception(new Throwable(""));
    } catch (Exception e) {
        assertTrue(countLines(ExceptionUtils.stackTrace(e.getCause(), "\n", 2)) > 3);
    }

}

From source file:com.ning.metrics.eventtracker.ScribeSender.java

@Override
public void send(Event event, CallbackHandler handler) {
    if (scribeClient == null) {
        handler.onError(new Throwable("Scribe client has not been set up correctly"), event);
        return;/*from  www . java  2  s. c  o  m*/
    }

    // Tell the watchdog that we are doing something
    sleeping.set(false);

    // TODO: offer batch API?, see drainEvents
    List<LogEntry> list = new ArrayList<LogEntry>(1);
    // TODO: update Scribe to pass a Thrift directly instead of serializing it

    final String logEntryMessage;
    try {
        logEntryMessage = eventToLogEntryMessage(event);
    } catch (IOException e) {
        handler.onError(new Throwable(e), event);
        return;
    }
    list.add(new LogEntry(event.getName(), logEntryMessage));

    try {
        scribeClient.log(list);
        messagesSuccessfullySent.addAndGet(list.size());
        messagesSuccessfullySentSinceLastReconnection.addAndGet(list.size());

        // For load balancing capabilities, we don't want to make sticky connections to Scribe.
        // After a certain threshold, force a refresh of the connection.
        if (messagesSuccessfullySentSinceLastReconnection.get() > messagesToSendBeforeReconnecting) {
            log.info("Recycling connection with Scribe");
            messagesSuccessfullySentSinceLastReconnection.set(0);
            createConnection();
        }
    } catch (org.apache.thrift.TException e) {
        // Connection flacky?
        log.warn(String.format("Error while sending message to Scribe: %s", e.getLocalizedMessage()));
        createConnection();
        handler.onError(new Throwable(e), event);
    }

    handler.onSuccess(event);
}