Skip to content

Commit c5e895a

Browse files
record exception handler
1 parent a3c89a8 commit c5e895a

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId = "co.ec.cnsyn.codecatcher"
1414
minSdk = 24
1515
targetSdk = 34
16-
versionCode = 129
17-
versionName = "1.0.129"
16+
versionCode = 130
17+
versionName = "1.0.130"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
vectorDrawables {

app/src/main/java/co/ec/cnsyn/codecatcher/ExceptionHandler.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,20 @@ class ExceptionHandler(private val context: Context) : Thread.UncaughtExceptionH
140140
logFile.writeText("")
141141
}
142142

143+
fun record(throwable: Throwable) {
144+
val logDir = getLogDirectory(App.context())
145+
val fileName = "crash_report_${System.currentTimeMillis() / 1000L}.txt"
146+
147+
val file = File(logDir, fileName)
148+
FileOutputStream(file).use { fos ->
149+
PrintWriter(fos).use { writer ->
150+
val sw = StringWriter()
151+
val pw = PrintWriter(sw)
152+
throwable.printStackTrace(pw)
153+
writer.println(sw.toString())
154+
}
155+
}
156+
}
157+
143158
}
144159
}

app/src/main/java/co/ec/cnsyn/codecatcher/helpers/util.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.ui.text.withStyle
1515
import androidx.core.view.ViewCompat
1616
import androidx.core.view.WindowInsetsCompat
1717
import co.ec.cnsyn.codecatcher.App
18+
import co.ec.cnsyn.codecatcher.ExceptionHandler
1819
import kotlin.concurrent.thread
1920

2021

@@ -43,10 +44,11 @@ fun <T : Any?> async(
4344
err(e)
4445
}
4546
if (e is NullPointerException){
46-
AppLogger.e("Async error ${e.stackTrace}",e,"async")
47+
AppLogger.e("Async error ${e.message}",e,"async")
4748
} else {
4849
AppLogger.e("Async error",e,"async")
4950
}
51+
ExceptionHandler.record(e)
5052
}
5153
}
5254
}

0 commit comments

Comments
 (0)