This library provides in-app errors catching and sending them to the Hawk monitoring system. You can also send errors, which you caught in try-catch.
Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add the dependency
<dependency>
<groupId>com.github.codex-team</groupId>
<artifactId>hawk.kotlin</artifactId>
<version>v3.0</version>
</dependency>
To connect the library, add the following code to your build.gradle config.
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
And the dependency on the library
dependencies {
implementation 'com.github.codex-team:hawk.kotlin:v3.0'
}
To activate the error collector, you can add the following code to your main class
val catcher: HawkExceptionCatcher = HawkCatcher(integrationToken)
.versionProvider(VersionProviderImpl())
.userProvider(UserProviderImpl())
.isDebug(true)
.build()
catcher.start()
Input parameters
integrationToken - unique key Hawk token
versionProvider - To provide the application version number and name
userProvider - to provide a unique user ID and user name
isDebug - if you need to display additional information
This example uses the default implementation of the specified providers. For more information you can read about interface VersionProvider and UserProvider.
Catching an UncaughtException
fun myTask() {
var d = 10 / 0;
}
myTask()
Sending caught exceptions
val catcher: HawkExceptionCatcher
fun myTask() {
try {
var d = 10 / 0
} catch(e: Exception) {
catcher.caught(e)
// This method generates an exception in JSON and sends it
}
}
myTask()
At the same time, errors caught in try-catch without using the caught() function will not be sent
fun myTask() {
try {
var d = 10 / 0
} catch(e: Exception) {
e.printStackTrace()
// The error will not be sent
}
}
myTask()
CodeX is a team of digital specialists around the world interested in building high-quality open source products on a global market. We are open for young people who want to constantly improve their skills and grow professionally with experiments in cutting-edge technologies.
🌐 | Join 👋 | ||
---|---|---|---|
codex.so | codex.so/join | @codex_team | @codex_team |