@Test public void testExceptionHandler() throws Exception { assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); track().uncaughtExceptions().with(mTracker); assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); try { //noinspection NumericOverflow int i = 1 / 0; assertNotEquals(i, 0); } catch (Exception e) { (Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e); } verify(mTracker).track(mCaptor.capture()); TrackMe tracked = mCaptor.getValue(); assertEquals(tracked.get(QueryParams.EVENT_CATEGORY), "Exception"); assertTrue(tracked.get(QueryParams.EVENT_ACTION).startsWith("org.matomo.sdk.extra.TrackHelperTest/testExceptionHandler:")); assertEquals(tracked.get(QueryParams.EVENT_NAME), "/ by zero"); assertEquals(tracked.get(QueryParams.EVENT_VALUE), "1"); boolean exception = false; try { track().uncaughtExceptions().with(mTracker); } catch (RuntimeException e) { exception = true; } assertTrue(exception); } }
@Test public void testExceptionHandler() throws Exception { assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); track().uncaughtExceptions().with(mTracker); assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); try { //noinspection NumericOverflow int i = 1 / 0; assertNotEquals(i, 0); } catch (Exception e) { (Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e); } verify(mTracker).track(mCaptor.capture()); TrackMe tracked = mCaptor.getValue(); assertEquals(tracked.get(QueryParams.EVENT_CATEGORY), "Exception"); assertTrue(tracked.get(QueryParams.EVENT_ACTION).startsWith("org.matomo.sdk.extra.TrackHelperTest/testExceptionHandler:")); assertEquals(tracked.get(QueryParams.EVENT_NAME), "/ by zero"); assertEquals(tracked.get(QueryParams.EVENT_VALUE), "1"); boolean exception = false; try { track().uncaughtExceptions().with(mTracker); } catch (RuntimeException e) { exception = true; } assertTrue(exception); } }
/** * This will create an exception handler that wraps any existing exception handler. * Exceptions will be caught, tracked, dispatched and then rethrown to the previous exception handler. * <p> * Be wary of relying on this for complete crash tracking.. * Think about how to deal with older app versions still throwing already fixed exceptions. * <p> * See discussion here: https://github.com/matomo-org/matomo-sdk-android/issues/28 */ public UncaughtExceptions uncaughtExceptions() { return new UncaughtExceptions(this); }
/** * This will create an exception handler that wraps any existing exception handler. * Exceptions will be caught, tracked, dispatched and then rethrown to the previous exception handler. * <p> * Be wary of relying on this for complete crash tracking.. * Think about how to deal with older app versions still throwing already fixed exceptions. * <p> * See discussion here: https://github.com/matomo-org/matomo-sdk-android/issues/28 */ public UncaughtExceptions uncaughtExceptions() { return new UncaughtExceptions(this); }