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

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