Skip to content

Commit 460120c

Browse files
authored
Don't override default uncaught exception handler (#20)
Save default exception handler when replacing it with WhatTheStack
1 parent 79034cf commit 460120c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

what-the-stack/src/main/java/com/haroldadmin/whatthestack/WhatTheStack.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ internal object InitializationManager {
3232
private val connection = WhatTheStackConnection(
3333
onConnected = { binder ->
3434
val messenger = Messenger(binder)
35-
val exceptionHandler = WhatTheStackExceptionHandler(messenger)
35+
val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
36+
val exceptionHandler = WhatTheStackExceptionHandler(messenger, defaultHandler)
3637
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler)
3738
}
3839
)

what-the-stack/src/main/java/com/haroldadmin/whatthestack/WhatTheStackExceptionHandler.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import androidx.core.os.bundleOf
1212
*/
1313

1414
internal class WhatTheStackExceptionHandler(
15-
private val service: Messenger
15+
private val service: Messenger,
16+
private val defaultHandler: Thread.UncaughtExceptionHandler?
1617
) : Thread.UncaughtExceptionHandler {
1718
override fun uncaughtException(t: Thread, e: Throwable) {
1819

@@ -27,6 +28,6 @@ internal class WhatTheStackExceptionHandler(
2728
)
2829
})
2930

30-
Process.killProcess(Process.myPid())
31+
defaultHandler?.uncaughtException(t, e) ?: Process.killProcess(Process.myPid())
3132
}
3233
}

0 commit comments

Comments
 (0)