@@ -58,6 +58,25 @@ public static void disableRxJava2AssemblyTracking() {
5858 RxJavaAssemblyTracking .disable ();
5959 }
6060
61+ /**
62+ * Obtain a copy of the original Throwable with an extended StackTrace
63+ * @param original Original Throwable
64+ * @return new Throwable with enhanced StackTrace if information was found. <i>null</i> otherwise
65+ */
66+ public static @ Nullable Throwable getEnhancedStackTrace (Throwable original ) {
67+ Throwable enhanced = original ;
68+
69+ RxJavaAssemblyException assembledException = RxJavaAssemblyException .find (original );
70+ if (assembledException != null ) {
71+ StackTraceElement [] clearStack = parseStackTrace (assembledException , basePackages );
72+ Throwable clearException = new Throwable ();
73+ clearException .setStackTrace (clearStack );
74+ enhanced = setRootCause (original , clearException , basePackages );
75+ }
76+
77+ return enhanced ;
78+ }
79+
6180 /**
6281 * Set handler to intercept an exception, improve the StackTrace of RxJava-related ones and rethrow let the exception go through
6382 */
@@ -66,17 +85,13 @@ private static void setRxJavaAssemblyHandler() {
6685 Thread .setDefaultUncaughtExceptionHandler (new Thread .UncaughtExceptionHandler () {
6786 @ Override
6887 public void uncaughtException (Thread t , Throwable e ) {
69- Throwable toThrow = e ;
88+ Throwable enhancedStackTrace = getEnhancedStackTrace ( e ) ;
7089
71- RxJavaAssemblyException assembledException = RxJavaAssemblyException .find (e );
72- if (assembledException != null ) {
73- StackTraceElement [] clearStack = parseStackTrace (assembledException , basePackages );
74- Throwable clearException = new Throwable ();
75- clearException .setStackTrace (clearStack );
76- toThrow = setRootCause (e , clearException , basePackages );
90+ if (enhancedStackTrace != null ) {
91+ previousDefaultHandler .uncaughtException (t , enhancedStackTrace );
92+ } else {
93+ previousDefaultHandler .uncaughtException (t , e );
7794 }
78-
79- previousDefaultHandler .uncaughtException (t , toThrow );
8095 }
8196 });
8297 }
0 commit comments