Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

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

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:com.testmax.uri.ExamplePerformance.java

private void threadExit() {
    String sql = "";
    try {//  w  w w  . j  a v  a2 s.  c o  m
        //insert a record 
        this.groupId++;
        sql = " INSERT INTO `automation`.`TABLE_PERFORMANCE_RESULT` ( `RunId`, `Host`, `PoleId`, `GroupId`, "
                + " `ThreadId`, `MatrixId`,`Browser`, `StartTime`, `EndTime`, `QuiteTime`, `ExecutionCount`, `AvgRespTime`, `TestDuration`,"
                + " `KeyValues`, `RunDate`, `ElaspedTimeMili`, `IdeaCount`, `CommentCount`,`VoteCount`,`CurrentStatus`) VALUES"
                + "( '" + runId + "', '" + host + "', '" + this.pollId + "', '" + this.groupId + "', '"
                + this.localuser + "', '" + this.matrixId + "','" + this.browser + "', ' ', ' ', ' ',0,"
                + this.avgTime + "," + this.page.getTimeOut() * 1000 + ",' ',now(),'0',0,0,0,'EXIT')";

        boolean status = dutl.executeQuery(sql, "automation");
    } catch (Exception e) {
        this.printMessage("FAILED : to insert Thread EXIT :" + sql + " \n" + e.getMessage());
        e.getStackTrace();
    }
}

From source file:com.viettel.ipcclib.CallActivity.java

@Override
public void onIceConnected() {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {
        @Override//from www. j  a  v a  2s  .c  o m
        public void run() {
            try {
                logAndToast("ICE connected, delay=" + delta + "ms");
                iceConnected = true;
                callConnected();
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
    });
}

From source file:org.rapidandroid.activity.FormReviewer.java

private void uploadFile(final String filename) {
    Toast.makeText(getApplicationContext(), FILE_UPLOAD_BEGUN, Toast.LENGTH_LONG).show();
    Thread t = new Thread() {
        @Override/*from  ww  w . j  a v a 2 s .  co m*/
        public void run() {
            try {
                DefaultHttpClient httpclient = new DefaultHttpClient();

                File f = new File(filename);

                HttpPost httpost = new HttpPost("http://192.168.7.127:8160/upload/upload");
                MultipartEntity entity = new MultipartEntity();
                entity.addPart("myIdentifier", new StringBody("somevalue"));
                entity.addPart("myFile", new FileBody(f));
                httpost.setEntity(entity);

                HttpResponse response;

                // Post, check and show the result (not really spectacular,
                // but works):
                response = httpclient.execute(httpost);

                Log.d("httpPost", "Login form get: " + response.getStatusLine());

                if (entity != null) {
                    entity.consumeContent();
                }

                success = true;
            } catch (Exception ex) {
                Log.d("FormReviewer",
                        "Upload failed: " + ex.getMessage() + " Stacktrace: " + ex.getStackTrace());
                success = false;
            } finally {
                mDebugHandler.post(mFinishUpload);
            }
        }
    };
    t.start();
}

From source file:com.viettel.ipcclib.CallActivity.java

@Override
public void onPeerConnectionStatsReady(final StatsReport[] reports) {
    runOnUiThread(new Runnable() {
        @Override/*from   ww  w. j  av  a 2 s  .  c  o m*/
        public void run() {
            if (!isError && iceConnected) {
                try {
                    hudFragment.updateEncoderStatistics(reports);
                } catch (Exception e) {
                    e.getStackTrace();
                }
            }
        }
    });
}

From source file:com.testmax.uri.ExamplePerformance.java

@Override
protected void teardown() {
    URLConfig urlConf = this.page.getPageURL().getUrlConfig(this.action);
    String historyid = urlConf.getUrlParamValue("historyid");
    String trakerid = urlConf.getUrlParamValue("trackerid");

    //print console
    //utl.afterMethod();

    threadExit();// www.  ja va 2  s  . c o  m
    try {
        String resp = utl.retrieveOutput(trakerid);
        String history = utl.retrieveOutput(historyid);
        this.printMessage("\nHISTORY-RESP :\n" + resp + "\nHISTORY:\n" + history);
        this.pollId = -1;
        this.groupId = -1;

        if (!utl.isEmptyValue(resp)) {
            String[] polls = resp.split("USER-POLL:");
            for (String poll : polls) {
                if (!utl.isEmptyValue(poll)) {
                    this.printMessage(
                            "\n Total Row=" + polls.length + "\nINSERTING  Data: " + "USER-POLL:" + poll);
                    handleResponse("USER-POLL:" + poll, "TABLE_PERFORMANCE_HISTORY");
                }
            }
        }

        if (!utl.isEmptyValue(history)) {
            String[] polls = history.split("USER-POLL:");
            for (String poll : polls) {
                if (!utl.isEmptyValue(poll)) {
                    this.printMessage(
                            "\n Total Row=" + polls.length + "\nINSERTING  Data: " + "USER-POLL:" + poll);
                    handleResponse("USER-POLL:" + poll, "TABLE_PERFORMANCE_HISTORY");
                }
            }
        }

    } catch (Exception e) {
        this.printMessage("FAILED : to insert History" + e.getMessage());
        e.getStackTrace();
    }

}

From source file:mp.paschalis.EditBookActivity.java

/**
 * Creates a sharing {@link Intent}./*from  www .j av a  2  s.  com*/
 *
 * @return The sharing intent.
 */
private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    String root = Environment.getExternalStorageDirectory() + ".SmartLib/Images";
    new File(root).mkdirs();

    File file = new File(root, app.selectedBook.isbn);

    try {
        FileOutputStream os = new FileOutputStream(file);
        bitmapBookCover.compress(CompressFormat.PNG, 80, os);
        os.flush();
        os.close();

        Uri uri = Uri.fromFile(file);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    } catch (Exception e) {
        Log.e(TAG, e.getStackTrace().toString());
    }

    String bookInfo = "\n\n\n\nMy " + getString(R.string.bookInfo) + ":\n" + getString(R.string.title)
            + ": \t\t\t\t" + app.selectedBook.title + "\n" + getString(R.string.author) + ": \t\t\t"
            + app.selectedBook.authors + "\n" + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn
            + "\n" + getString(R.string.published_) + " \t" + app.selectedBook.publishedYear + "\n"
            + getString(R.string.pages_) + " \t\t\t" + app.selectedBook.pageCount + "\n"
            + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn + "\n"
            + getString(R.string.status) + ": \t\t\t"
            + App.getBookStatusString(app.selectedBook.status, EditBookActivity.this) + "\n\n"
            + "http://books.google.com/books?vid=isbn" + app.selectedBook.isbn;

    shareIntent.putExtra(Intent.EXTRA_TEXT, bookInfo);

    return shareIntent;
}

From source file:com.collabnet.ccf.core.hospital.CCFExceptionToOrderedMapConvertor.java

/**
 * Converts the <code>record</code> into an <code>IOrderedMap</code> .
 * /*from   w ww.  j a  v a 2s . c  o  m*/
 * @param record
 *            Object which should be a MessageException instance
 * @return an IOrderedMap representation of the MessageException contents
 */
protected Object convert(Object record) {
    try {
        boolean quarantineException = true;

        // we have to set these columns due to an SQL incompatibility issue
        // with
        // these fields
        setFixedColName(FIXED);
        setReprocessedColName(REPROCESSED);

        // log.warn("Artifact reached ambulance");
        // first of all we pass the record in our parent method
        Object preprocessedMap = super.convert(record);
        if (preprocessedMap == null || (!(preprocessedMap instanceof IOrderedMap))) {
            return preprocessedMap;
        }
        IOrderedMap map = (IOrderedMap) preprocessedMap;

        // remove entities with wrong data type (string instead of boolean)
        map.remove(FIXED);
        map.remove(REPROCESSED);

        map.put(FIXED, false);
        map.put(REPROCESSED, false);

        MessageException messageException = (MessageException) record;
        map.put(exceptionMessageColName, messageException.getException().getMessage());

        Throwable cause = messageException.getException().getCause();
        if (cause != null) {
            map.put(causeExceptionClassColName, cause.getClass().getName());
            map.put(causeExceptionMessageColName, cause.getMessage());
        } else {
            map.put(causeExceptionClassColName, NO_CAUSE_EXCEPTION);
            map.put(causeExceptionMessageColName, NO_CAUSE_EXCEPTION);
        }

        Exception exception = messageException.getException();
        StringBuffer stackTraceBuf = new StringBuffer();
        StackTraceElement[] stackTrace = exception.getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
            stackTraceBuf.append(stackTrace[i]);
            stackTraceBuf.append("\n");
        }
        /* Append cause exception stack trace */
        if (cause != null) {
            stackTraceBuf.append("\n\n");
            stackTrace = cause.getStackTrace();
            for (int i = 0; i < stackTrace.length; i++) {
                stackTraceBuf.append(stackTrace[i]);
                stackTraceBuf.append("\n");
            }
        }
        map.put(stackTraceColName, stackTraceBuf.toString());

        String adaptorName = null == adaptor ? "Unknown" : adaptor.getId();
        map.put(adaptorColName, adaptorName);

        Object data = messageException.getData();
        String dataType = null;
        if (data != null) {
            dataType = data.getClass().getName();
        }
        map.put(dataTypeColName, dataType);
        Element element = null;
        Document dataDoc = null;
        if (data instanceof Document) {
            dataDoc = (Document) data;
            element = dataDoc.getRootElement();
        }
        if (element != null) {
            try {
                GenericArtifact ga = GenericArtifactHelper.createGenericArtifactJavaObject(dataDoc);

                String sourceArtifactId = ga.getSourceArtifactId();
                String sourceSystemId = ga.getSourceSystemId();
                String sourceSystemKind = ga.getSourceSystemKind();
                String sourceRepositoryId = ga.getSourceRepositoryId();
                String sourceRepositoryKind = ga.getSourceRepositoryKind();

                String targetArtifactId = ga.getTargetArtifactId();
                String targetSystemId = ga.getTargetSystemId();
                String targetSystemKind = ga.getTargetSystemKind();
                String targetRepositoryId = ga.getTargetRepositoryId();
                String targetRepositoryKind = ga.getTargetRepositoryKind();

                String artifactErrorCode = ga.getErrorCode();

                String sourceArtifactLastModifiedDateString = ga.getSourceArtifactLastModifiedDate();
                String targetArtifactLastModifiedDateString = ga.getTargetArtifactLastModifiedDate();
                String sourceArtifactVersion = ga.getSourceArtifactVersion();
                String targetArtifactVersion = ga.getTargetArtifactVersion();

                String artifactType = XPathUtils.getAttributeValue(element,
                        GenericArtifactHelper.ARTIFACT_TYPE);

                Date sourceLastModifiedDate = null;
                if (!sourceArtifactLastModifiedDateString.equalsIgnoreCase(GenericArtifact.VALUE_UNKNOWN)) {
                    sourceLastModifiedDate = DateUtil.parse(sourceArtifactLastModifiedDateString);
                } else {
                    // use the earliest date possible
                    sourceLastModifiedDate = new Date(0);
                }
                if (sourceLastModifiedDate == null) {
                    sourceLastModifiedDate = new Date(0);
                }
                java.sql.Timestamp sourceTime = new Timestamp(sourceLastModifiedDate.getTime());

                java.util.Date targetLastModifiedDate = null;
                if (!targetArtifactLastModifiedDateString.equalsIgnoreCase(GenericArtifact.VALUE_UNKNOWN)) {
                    targetLastModifiedDate = DateUtil.parse(targetArtifactLastModifiedDateString);
                } else {
                    // use the earliest date possible
                    targetLastModifiedDate = new Date(0);
                }
                java.sql.Timestamp targetTime = new Timestamp(targetLastModifiedDate.getTime());

                // TODO Should we allow to set different column names for
                // these
                // properties?
                map.put(SOURCE_SYSTEM_ID, sourceSystemId);
                map.put(SOURCE_REPOSITORY_ID, sourceRepositoryId);
                map.put(TARGET_SYSTEM_ID, targetSystemId);
                map.put(TARGET_REPOSITORY_ID, targetRepositoryId);
                map.put(SOURCE_SYSTEM_KIND, sourceSystemKind);
                map.put(SOURCE_REPOSITORY_KIND, sourceRepositoryKind);
                map.put(TARGET_SYSTEM_KIND, targetSystemKind);
                map.put(TARGET_REPOSITORY_KIND, targetRepositoryKind);
                map.put(SOURCE_ARTIFACT_ID, sourceArtifactId);
                map.put(TARGET_ARTIFACT_ID, targetArtifactId);
                map.put(ERROR_CODE, artifactErrorCode);
                map.put(SOURCE_LAST_MODIFICATION_TIME, sourceTime);
                map.put(TARGET_LAST_MODIFICATION_TIME, targetTime);
                map.put(SOURCE_ARTIFACT_VERSION, sourceArtifactVersion);
                map.put(TARGET_ARTIFACT_VERSION, targetArtifactVersion);
                map.put(ARTIFACT_TYPE, artifactType);
                //log.info("Removing invalid XML characters if any before we proceed ...");
                map.put(GENERICARTIFACT, removeInvalidXmlCharacters(dataDoc.asXML()));

                // these attributes will be considered for CCF 2.x only
                map.put(DESCRIPTION, "This hospital entry has been inserted by CCF Core.");
                map.put(REPOSITORY_MAPPING_DIRECTION, sourceSystemKind);
                map.put(VERSION, 0);

            } catch (GenericArtifactParsingException e) {
                // log
                // .warn(
                // "The data that reached the hospital is not a valid Generic Artifact"
                // );
                if (isOnlyQuarantineGenericArtifacts()) {
                    quarantineException = false;
                }
                map.put(SOURCE_SYSTEM_ID, null);
                map.put(SOURCE_REPOSITORY_ID, null);
                map.put(TARGET_SYSTEM_ID, null);
                map.put(TARGET_REPOSITORY_ID, null);
                map.put(SOURCE_SYSTEM_KIND, null);
                map.put(SOURCE_REPOSITORY_KIND, null);
                map.put(TARGET_SYSTEM_KIND, null);
                map.put(TARGET_REPOSITORY_KIND, null);
                map.put(SOURCE_ARTIFACT_ID, null);
                map.put(TARGET_ARTIFACT_ID, null);
                //log.info("Removing invalid XML characters if any before we proceed ...");
                map.put(GENERICARTIFACT, removeInvalidXmlCharacters(dataDoc.asXML()));
                map.put(ERROR_CODE, null);
                map.put(SOURCE_LAST_MODIFICATION_TIME, null);
                map.put(TARGET_LAST_MODIFICATION_TIME, null);
                map.put(SOURCE_ARTIFACT_VERSION, null);
                map.put(TARGET_ARTIFACT_VERSION, null);
                map.put(ARTIFACT_TYPE, null);
            }
        } else {
            if (isOnlyQuarantineGenericArtifacts()) {
                quarantineException = false;
            }
            map.put(SOURCE_SYSTEM_ID, null);
            map.put(SOURCE_REPOSITORY_ID, null);
            map.put(TARGET_SYSTEM_ID, null);
            map.put(TARGET_REPOSITORY_ID, null);
            map.put(SOURCE_SYSTEM_KIND, null);
            map.put(SOURCE_REPOSITORY_KIND, null);
            map.put(TARGET_SYSTEM_KIND, null);
            map.put(TARGET_REPOSITORY_KIND, null);
            map.put(SOURCE_ARTIFACT_ID, null);
            map.put(TARGET_ARTIFACT_ID, null);
            map.put(GENERICARTIFACT, null);
            map.put(ERROR_CODE, null);
            map.put(SOURCE_LAST_MODIFICATION_TIME, null);
            map.put(TARGET_LAST_MODIFICATION_TIME, null);
            map.put(SOURCE_ARTIFACT_VERSION, null);
            map.put(TARGET_ARTIFACT_VERSION, null);
            map.put(ARTIFACT_TYPE, null);
        }

        if (quarantineException) {
            // TODO Do we have to care about the fact that the substituted
            // values
            // could potentially contain the place holders again?
            String logMessage = logMessageTemplate;
            for (Object key : map.keys()) {
                Object value = map.get(key);
                logMessage = logMessage.replace("<" + key.toString() + ">",
                        value == null ? "undefined" : value.toString());
            }
            log.error(logMessage);
            return map;
        } else {
            StringBuffer errorMessage = new StringBuffer();
            errorMessage.append("Exception caught that is not going to be quarantined. Characteristics:\n");
            for (Object key : map.keys()) {
                errorMessage.append(key.toString() + ": " + map.get(key) + "\n");
            }
            log.warn(errorMessage.toString());
            return null;
        }
    } catch (Exception e) {
        log.error("While trying to quarantine an exception, an exception occured", e);
        return null;
    }
}

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#getFeed(org.apache.lucene.gdata.data.ServerBaseFeed)
 *///from w  ww.j  a v a2  s .c o  m
@SuppressWarnings("unchecked")
public BaseFeed getFeed(final ServerBaseFeed feed) throws StorageException {

    if (feed == null)
        throw new StorageException("feed is null");
    if (LOG.isInfoEnabled())
        LOG.info("get feed: " + feed.getId() + " start-index: " + feed.getStartIndex() + " resultCount: "
                + feed.getItemsPerPage());
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        BaseFeed retVal = query.get().getLatestFeedQuery(feed.getId(), feed.getItemsPerPage(),
                feed.getStartIndex(), feed.getServiceConfig());
        return retVal;
    } catch (Exception e) {
        LOG.error("Can't get latest feed for feedID: " + feed.getId() + " -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't create Entry -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }

}

From source file:nl.b3p.kaartenbalie.service.servlet.CallWMSServlet.java

private void handleRequestExceptionAsImage(Exception ex, DataWrapper data) throws IOException {
    String message = ex.getMessage();
    try {//from  w w w  .  j  a va 2s  . com
        ExceptionLayer el = new ExceptionLayer();
        Map parameterMap = new HashMap();
        parameterMap.put("type", ex.getClass());
        parameterMap.put("transparant", Boolean.TRUE);
        parameterMap.put("message", message);
        parameterMap.put("stacktrace", ex.getStackTrace());
        el.sendImage(data, el.drawImage(data.getOgcrequest(), parameterMap));
    } catch (Exception e) {
        log.error("error handling exception: ", e);
        TextToImage tti = new TextToImage();
        try {
            tti.createImage(message, data);
        } catch (Exception lex) {
            log.error("error creating error-image: ", lex);
        }
    }
}

From source file:com.strandls.alchemy.rest.client.AlchemyRestClientFactoryTest.java

/**
 * Test method for//from w ww. j  a v a  2  s . c  o  m
 * {@link com.strandls.alchemy.rest.client.AlchemyRestClientFactory#getInstance(java.lang.Class, java.lang.String, javax.ws.rs.client.Client)}
 * .
 *
 * Test generic exception is relayed correctly without loosing message.
 *
 * @throws Exception
 */
@Test
public void testExceptionMapping() throws Exception {
    final TestWebserviceExceptionHandling service = clientFactory
            .getInstance(TestWebserviceExceptionHandling.class);
    try {
        service.fail();
        fail("Should have thrown an exception");
    } catch (final Exception e) {
        assertEquals(TestWebserviceExceptionHandling.EXCEPTION_STRING, e.getMessage());

        // ensure the mixin got applied
        assertNull(e.getCause());
        // ensure server stack trace is masked.
        // will have local stack trace though.
        final StackTraceElement[] stackTrace = e.getStackTrace();
        for (final StackTraceElement stackTraceElement : stackTrace) {
            assertFalse(stackTraceElement.toString()
                    .contains(TestWebserviceExceptionHandling.class.getName() + ".fail"));
        }
        assertEquals(0, e.getSuppressed().length);

    }

}