ExceptionReporter
Stay organized with collections
Save and categorize content based on your preferences.
Used to catch any uncaught exceptions and report them to Google Analytics. This class will
call GoogleAnalytics.dispatchLocalHits()
after calling Tracker.send(Map)
.
The exact message reported is determined by the ExceptionParser
set via the setExceptionParser(ExceptionParser)
method. See StandardExceptionParser
for an example of an implementation of ExceptionParser
.
All exceptions reported via this class will be reported as fatal exceptions.
Usage:
UncaughtExceptionHandler myHandler = new ExceptionReporter(
myTracker, // Currently used Tracker.
Thread.getDefaultUncaughtExceptionHandler(), // Current default uncaught exception handler.
context); // Context of the application.
// Make myHandler the new default uncaught exception handler.
Thread.setDefaultUncaughtExceptionHandler(myHandler);
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
From interface
java.lang.Thread.UncaughtExceptionHandler
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eExceptionReporter\u003c/code\u003e is used to catch uncaught exceptions within an application and send reports to Google Analytics.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes an \u003ccode\u003eExceptionParser\u003c/code\u003e to format the exception details for reporting, with \u003ccode\u003eStandardExceptionParser\u003c/code\u003e provided as a default implementation.\u003c/p\u003e\n"],["\u003cp\u003eAll exceptions captured by \u003ccode\u003eExceptionReporter\u003c/code\u003e are categorized as fatal.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers integrate it by creating an \u003ccode\u003eExceptionReporter\u003c/code\u003e instance and setting it as the default uncaught exception handler using \u003ccode\u003eThread.setDefaultUncaughtExceptionHandler()\u003c/code\u003e.\u003c/p\u003e\n"]]],["The `ExceptionReporter` class catches uncaught exceptions and reports them to Google Analytics as fatal errors. It implements `Thread.UncaughtExceptionHandler` and utilizes a `Tracker` instance. Upon catching an exception, it uses `Tracker.send()` and calls `GoogleAnalytics.dispatchLocalHits()`. The `ExceptionParser` determines the reported message and is set via `setExceptionParser()`. Usage involves creating a new `ExceptionReporter` and setting it as the default uncaught exception handler. The class's method are `getExceptionParser`, `setExceptionParser` and `uncaughtException`\n"],null,["# ExceptionReporter\n\npublic class **ExceptionReporter** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nimplements [Thread.UncaughtExceptionHandler](//developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html) \nUsed to catch any uncaught exceptions and report them to Google Analytics. This class will\ncall [GoogleAnalytics.dispatchLocalHits()](/android/reference/com/google/android/gms/analytics/GoogleAnalytics#dispatchLocalHits()) after calling [Tracker.send(Map)](/android/reference/com/google/android/gms/analytics/Tracker#send(java.util.Map\u003cjava.lang.String,%20java.lang.String\u003e)).\n\nThe exact message reported is determined by the [ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser)\nset via the [setExceptionParser(ExceptionParser)](/android/reference/com/google/android/gms/analytics/ExceptionReporter#setExceptionParser(com.google.android.gms.analytics.ExceptionParser)) method. See [StandardExceptionParser](/android/reference/com/google/android/gms/analytics/StandardExceptionParser)\nfor an example of an implementation of [ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser).\n\nAll exceptions reported via this class will be reported as fatal exceptions.\n\nUsage: \n\n```\n UncaughtExceptionHandler myHandler = new ExceptionReporter(\n myTracker, // Currently used Tracker.\n Thread.getDefaultUncaughtExceptionHandler(), // Current default uncaught exception handler.\n context); // Context of the application.\n\n // Make myHandler the new default uncaught exception handler.\n Thread.setDefaultUncaughtExceptionHandler(myHandler);\n \n``` \n\n### Public Constructor Summary\n\n|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [ExceptionReporter](/android/reference/com/google/android/gms/analytics/ExceptionReporter#ExceptionReporter(com.google.android.gms.analytics.Tracker,%20java.lang.Thread.UncaughtExceptionHandler,%20android.content.Context))([Tracker](/android/reference/com/google/android/gms/analytics/Tracker) tracker, [Thread.UncaughtExceptionHandler](//developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html) originalHandler, [Context](//developer.android.com/reference/android/content/Context.html) context) |\n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser) | [getExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionReporter#getExceptionParser())() |\n| void | [setExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionReporter#setExceptionParser(com.google.android.gms.analytics.ExceptionParser))([ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser) exceptionParser) |\n| void | [uncaughtException](/android/reference/com/google/android/gms/analytics/ExceptionReporter#uncaughtException(java.lang.Thread,%20java.lang.Throwable))([Thread](//developer.android.com/reference/java/lang/Thread.html) t, [Throwable](//developer.android.com/reference/java/lang/Throwable.html) e) |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.Thread.UncaughtExceptionHandler \n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | uncaughtException([Thread](//developer.android.com/reference/java/lang/Thread.html) arg0, [Throwable](//developer.android.com/reference/java/lang/Throwable.html) arg1) |\n\nPublic Constructors\n-------------------\n\n#### public **ExceptionReporter** ([Tracker](/android/reference/com/google/android/gms/analytics/Tracker) tracker, [Thread.UncaughtExceptionHandler](//developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html) originalHandler, [Context](//developer.android.com/reference/android/content/Context.html) context)\n\n##### Parameters\n\n| tracker | an active [Tracker](/android/reference/com/google/android/gms/analytics/Tracker) instance. Should not be null. |\n| originalHandler | the current `DefaultUncaughtExceptionHandler`. |\n| context | the current app context. Should not be null. |\n|-----------------|----------------------------------------------------------------------------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public [ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser)\n**getExceptionParser** ()\n\n#### public void **setExceptionParser** ([ExceptionParser](/android/reference/com/google/android/gms/analytics/ExceptionParser) exceptionParser)\n\n#### public void **uncaughtException** ([Thread](//developer.android.com/reference/java/lang/Thread.html) t, [Throwable](//developer.android.com/reference/java/lang/Throwable.html) e)"]]