Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:MainClass.java

public MainClass() {
    Container cp = getContentPane();
    JButton crasher = new JButton("Crash");
    cp.add(crasher);//from w  w w  . j  a v  a 2s.c  o m
    crasher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            throw new RuntimeException("You asked for it");
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable ex) {
            System.out.println("You crashed thread " + t.getName());
            System.out.println("Exception was: " + ex.toString());
        }
    });
    pack();
}

From source file:com.ChatEndpoint.java

@OnError
public void onError(Throwable t) {
    log.info(t.toString());
}

From source file:com.vmware.photon.controller.api.client.resource.SystemStatusApiTest.java

@Test
public void testGetVmAsync() throws IOException, InterruptedException {
    final SystemStatus systemStatus = new SystemStatus();
    systemStatus.setStatus(StatusType.READY);

    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(systemStatus);

    setupMocks(serialized, HttpStatus.SC_OK);

    SystemStatusApi systemStatusApi = new SystemStatusApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    systemStatusApi.getSystemStatusAsync(new FutureCallback<SystemStatus>() {
        @Override/*from   ww w. j a v  a2  s.  c om*/
        public void onSuccess(@Nullable SystemStatus result) {
            assertEquals(result, systemStatus);
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.api.client.resource.SystemStatusRestApiTest.java

@Test
public void testGetVmAsync() throws IOException, InterruptedException {
    final SystemStatus systemStatus = new SystemStatus();
    systemStatus.setStatus(StatusType.READY);

    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(systemStatus);

    setupMocks(serialized, HttpStatus.SC_OK);

    SystemStatusApi systemStatusApi = new SystemStatusRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    systemStatusApi.getSystemStatusAsync(new FutureCallback<SystemStatus>() {
        @Override//from ww  w.  j av  a 2 s .  c  om
        public void onSuccess(@Nullable SystemStatus result) {
            assertEquals(result, systemStatus);
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:de.langmi.spring.batch.examples.complex.skip.policy.simple.SkipJobPolicy.java

@Override
public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException {
    LOG.debug("shouldSkip:" + t.toString());
    if (t instanceof SkipJobCustomException && skipCount <= skipLimit) {
        return true;
    } else {//from  w  w w.  j  a va2  s .  c o m
        return false;
    }
}

From source file:io.github.retz.scheduler.AdminConsole.java

@Override
public boolean gc(int leeway) {
    try {//  ww  w .j a v a 2  s . co m
        // TODO: do we do mutex to avoid concurrent execution even though it has transaction?
        LOG.info("Job GC invocation from JMX: leeway={}s", leeway);
        Database.getInstance().deleteOldJobs(LEEWAY);
        return true;
    } catch (Throwable t) {
        LOG.info(t.toString(), t);
        return false;
    }
}

From source file:com.example.android.cardreader.MainActivity.java

public static void queryId(String id) {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get("http://apis.scottylabs.org/directory/v1/andrewID/" + id, new AsyncHttpResponseHandler() {
        @Override//from   www.j  ava2s. c  om
        public void onSuccess(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes) {
            String response = new String(bytes);
            System.out.println("Response=" + response);
            try {
                JSONObject jsonObject = new JSONObject(response);
                String fullName = jsonObject.getString("first_name") + " " + jsonObject.getString("last_name");
                nameField.setText(fullName);
            } catch (Exception e) {
                e.printStackTrace();
            }
            YoYo.with(Techniques.FadeIn).duration(300).withListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    nameField.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animation) {

                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            }).playOn(nameField);
            YoYo.with(Techniques.FadeIn).duration(300).withListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    scanView.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animation) {

                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            }).playOn(scanView);
            YoYo.with(Techniques.FadeOut).duration(300).withListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    pb.setVisibility(View.INVISIBLE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            }).playOn(pb);
            Globals.adding = true;
        }

        @Override
        public void onFailure(int i, cz.msebera.android.httpclient.Header[] headers, byte[] bytes,
                Throwable throwable) {
            System.out.println("Failed with " + throwable.toString());
            if (pb.getVisibility() == View.VISIBLE) {
                YoYo.with(Techniques.FadeOut).duration(1).withListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        pb.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                }).playOn(pb);
                YoYo.with(Techniques.FadeOut).duration(1).withListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        nameField.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                }).playOn(nameField);
                YoYo.with(Techniques.FadeOut).duration(1).withListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        scanView.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                }).playOn(scanView);
            }
            Globals.adding = false;
        }
    });
}

From source file:ErrorHandlerTest.java

public void handle(Throwable t) {
    System.err.println("Hey, I caught it!");
    System.err.println(t.toString());
}

From source file:com.ning.billing.analytics.dao.TestEventDao.java

@BeforeClass(alwaysRun = true)
public void startMysql() throws IOException, ClassNotFoundException, SQLException {
    final String ddl = IOUtils
            .toString(EventDao.class.getResourceAsStream("/com/ning/billing/analytics/ddl.sql"));

    helper.startMysql();/*ww  w.  ja  v a  2  s  .  c  om*/
    helper.initDb(ddl);

    final IProduct product = new MockProduct("platinium", "subscription", ProductCategory.BASE);
    final IPlan plan = new MockPlan("platinum-monthly", product);
    final IPlanPhase phase = new MockPhase(PhaseType.EVERGREEN, plan, MockDuration.UNLIMITED(), 25.95);

    final BusinessSubscription prevSubscription = new BusinessSubscription(plan, phase, Currency.USD,
            new DateTime(DateTimeZone.UTC), ISubscription.SubscriptionState.ACTIVE, UUID.randomUUID(),
            UUID.randomUUID());
    final BusinessSubscription nextSubscription = new BusinessSubscription(plan, phase, Currency.USD,
            new DateTime(DateTimeZone.UTC), ISubscription.SubscriptionState.CANCELLED, UUID.randomUUID(),
            UUID.randomUUID());
    final BusinessSubscriptionEvent event = BusinessSubscriptionEvent.subscriptionCancelled(plan);
    final DateTime requestedTimestamp = new DateTime(DateTimeZone.UTC);

    transition = new BusinessSubscriptionTransition(KEY, requestedTimestamp, event, prevSubscription,
            nextSubscription);

    final IDBI dbi = helper.getDBI();
    dao = dbi.onDemand(EventDao.class);

    // Healthcheck test to make sure MySQL is setup properly
    try {
        dao.test();
    } catch (Throwable t) {
        Assert.fail(t.toString());
    }
}

From source file:com.cognifide.aet.validation.impl.ValidationUtilsTest.java

@Test
public void validationResultToString_whenResultBuilderHasErrorsAndThrowable_expectMessageWithCause()
        throws Exception {
    Throwable throwable = Mockito.mock(Throwable.class);
    when(throwable.toString()).thenReturn("EXCEPTION");
    when(errorMessage.getThrowable()).thenReturn(throwable);
    String result = ValidationUtils.validationResultToString(builderWithErrors);
    assertThat(result, is(// w  w w.ja  v  a  2 s  . co  m
            "Validation failed. 1 errors were found:\nError 1\n\tMessage: message\n\tCaused by: EXCEPTION\n"));
}