Get most of the exception stacktrace in CrashActivity before a NPE occurs

This commit is contained in:
Shinokuni 2024-08-16 18:06:54 +02:00
parent 1cb6c92edf
commit 8e44b8a097
1 changed files with 10 additions and 6 deletions

View File

@ -44,6 +44,8 @@ import com.readrops.app.util.theme.ShortSpacer
import com.readrops.app.util.theme.VeryLargeSpacer
import com.readrops.app.util.theme.VeryShortSpacer
import com.readrops.app.util.theme.spacing
import java.io.PrintWriter
import java.io.StringWriter
class CrashActivity : ComponentActivity() {
@ -55,17 +57,19 @@ class CrashActivity : ComponentActivity() {
val throwable = intent.getSerializableExtra(THROWABLE_KEY) as Throwable?
val stackTrace = try {
throwable?.stackTraceToString()
val sw = StringWriter()
val pw = PrintWriter(sw)
try {
throwable?.printStackTrace(pw)
} catch (e: Exception) {
Log.e("CrashActivity", "Unable to get crash exception")
throwable?.let { it::class.simpleName + it.message }
Log.e("CrashActivity", "couldn't get full exception stacktrace")
}
pw.flush()
setContent {
ReadropsTheme {
CrashScreen(stackTrace.orEmpty())
CrashScreen(sw.toString())
}
}
}