<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Show crash report metrics with custom error handler in Open Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Open-Q-A/Show-crash-report-metrics-with-custom-error-handler/m-p/234111#M30450</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In an Android app, I am implementing a custom caught exception handler to add specific behavior when an uncaught exception is encountered instead of allowing the app to crash. &lt;STRONG&gt;However, I still need to report crashes prevnted by the exception handler in Dynatrace for app's metrics.&lt;/STRONG&gt; The app currently uses &lt;EM&gt;com.dynatrace.tools.android:gradle-plugin:8.273.1.1003&lt;/EM&gt; for action and event monitoring.&lt;/P&gt;
&lt;P&gt;Currently, when I add the custom exception handler, the app crashes no longer show in Dynatrace Managed -&amp;gt; Applications -&amp;gt; AppName -&amp;gt; Crash Analysis.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have looked in the Dynatrace APIs, but have not found a way to still report crashes with the custom exception handler, only to report errors. &lt;STRONG&gt;Is there a way to add code to manually report a crash or have a caught exception still show in the crash statistics? Thank you!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;class UniversalExceptionHandler @Inject constructor(...) : Thread.UncaughtExceptionHandler {

    override fun uncaughtException(thread: Thread, exception: Throwable) {
        // custom code for handling uncaught exceptions instead of crashing
    }
}&lt;/PRE&gt;
&lt;PRE&gt;class MyAndroidApplication : Application(), HasAndroidInjector {

    override fun onCreate() {
        super.onCreate()&lt;BR /&gt;        // set custom exception handler
        Thread.setDefaultUncaughtExceptionHandler(universalExceptionHandler)
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2024 08:30:18 GMT</pubDate>
    <dc:creator>rwise25</dc:creator>
    <dc:date>2024-01-24T08:30:18Z</dc:date>
    <item>
      <title>Show crash report metrics with custom error handler</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Show-crash-report-metrics-with-custom-error-handler/m-p/234111#M30450</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In an Android app, I am implementing a custom caught exception handler to add specific behavior when an uncaught exception is encountered instead of allowing the app to crash. &lt;STRONG&gt;However, I still need to report crashes prevnted by the exception handler in Dynatrace for app's metrics.&lt;/STRONG&gt; The app currently uses &lt;EM&gt;com.dynatrace.tools.android:gradle-plugin:8.273.1.1003&lt;/EM&gt; for action and event monitoring.&lt;/P&gt;
&lt;P&gt;Currently, when I add the custom exception handler, the app crashes no longer show in Dynatrace Managed -&amp;gt; Applications -&amp;gt; AppName -&amp;gt; Crash Analysis.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have looked in the Dynatrace APIs, but have not found a way to still report crashes with the custom exception handler, only to report errors. &lt;STRONG&gt;Is there a way to add code to manually report a crash or have a caught exception still show in the crash statistics? Thank you!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;class UniversalExceptionHandler @Inject constructor(...) : Thread.UncaughtExceptionHandler {

    override fun uncaughtException(thread: Thread, exception: Throwable) {
        // custom code for handling uncaught exceptions instead of crashing
    }
}&lt;/PRE&gt;
&lt;PRE&gt;class MyAndroidApplication : Application(), HasAndroidInjector {

    override fun onCreate() {
        super.onCreate()&lt;BR /&gt;        // set custom exception handler
        Thread.setDefaultUncaughtExceptionHandler(universalExceptionHandler)
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 08:30:18 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Show-crash-report-metrics-with-custom-error-handler/m-p/234111#M30450</guid>
      <dc:creator>rwise25</dc:creator>
      <dc:date>2024-01-24T08:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Show Crash Report Metrics with Custom Error Handler</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Show-crash-report-metrics-with-custom-error-handler/m-p/234364#M30522</link>
      <description>&lt;P&gt;Hey rwise25,&lt;BR /&gt;Android only supports one Thread.UncaughtExceptionHandler. By using the method Thread.setDefaultUncaughtExceptionHandler, you are removing the crash reporting capability of OneAgent for Android. Crash reporting tools like Dynatrace are preserving the original handler and forwarding the crash information to them to ensure that multiple handlers can be used at the same time. Normally, we would recommend adding the same logic to the custom handler:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;override fun uncaughtException(thread: Thread, exception: Throwable) {
	// custom logic
	
	// forward the crash to the next Thread.UncaughtExceptionHandler
	originalHandler?.uncaughtException(thread, exception)
}&lt;/LI-CODE&gt;&lt;P&gt;The original handler can be obtained via the method &lt;A href="https://developer.android.com/reference/java/lang/Thread#getDefaultUncaughtExceptionHandler()" target="_self"&gt;getDefaultUncaughtExceptionHandler&lt;/A&gt; before it is replaced with setDefaultUncaughtExceptionHandler.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;When you want to replace the default app crash behavior, then you can't use this solution. Because OneAgent will notify the Android OS and the system will terminate the application. In this case, you have to report the uncaught exception as error, because it is now a "caught exception" and the user session continues.&lt;BR /&gt;&lt;BR /&gt;Instead of the crash analysis screen, you can use the multidimensional analysis and error details screen to analyze the reported exceptions.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 16:40:57 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Show-crash-report-metrics-with-custom-error-handler/m-p/234364#M30522</guid>
      <dc:creator>Thomas_Wirth1</dc:creator>
      <dc:date>2024-01-15T16:40:57Z</dc:date>
    </item>
  </channel>
</rss>

