Skip to content

Commit

Permalink
Add CUncaughtExceptionHandler class.
Browse files Browse the repository at this point in the history
  • Loading branch information
xbdcc committed Oct 29, 2019
1 parent d4a742a commit 2ea9dbe
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* `19/10/29` Add CUncaughtExceptionHandler class.
* `19/10/10` Add AOP annotation tool class to prevent repteated clicks.
* `19/10/09` Add ViewExtend class and update Android Studio to 3.5.1.
* `19/09/24` Add TimerHelper tool class. (v0.0.19)
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- Add the following dependency to your `build.gradle` file.
```
implementation 'com.github.xbdcc:cutils:0.0.19'
implementation 'com.github.xbdcc:cutils:0.0.20'
```


Expand All @@ -29,8 +29,12 @@
- [打印日志工具类](notes/util/ActivityCollectorUtils.md) -> [LogUtils.kt][LogUtils.kt]
- [无障碍服务工具类](notes/util/AccessibilityServiceUtils.md) -> [AccessibilityServiceUtils.kt][AccessibilityServiceUtils.kt]
- [Kotlin中View扩展工具类](notes/util/ViewExtend.md) -> [ViewExtend.kt][ViewExtend.kt]
- [防重复点击工具类](notes/util/ViewExtend.md) -> [ViewExtend.kt][ViewExtend.kt]
- [AOP注解防重复点击工具类](notes/util/CSingleClick.md) -> [CSingleClick.kt][CSingleClick.kt]
- [防重复点击工具类](notes/extend/ViewExtend.md) ->
[ViewExtend.kt][ViewExtend.kt]
- [AOP注解防重复点击工具类](notes/util/CSingleClick.md) ->
[CSingleClick.kt][CSingleClick.kt]
- [全局捕获未捕获异常类](notes/execption/CUncaughtExceptionHandler.md) ->
[CUncaughtExceptionHandler.kt][CUncaughtExceptionHandler.kt]

[DeviceUtils.kt]: cutils/src/main/java/com/carlos/cutils/util/DeviceUtils.kt
[AppUtils.kt]: cutils/src/main/java/com/carlos/cutils/util/AppUtils.kt
Expand All @@ -40,4 +44,5 @@
[AccessibilityServiceUtils.kt]: cutils/src/main/java/com/carlos/cutils/util/AccessibilityServiceUtils.kt
[ViewExtend.kt]: cutils/src/main/java/com/carlos/cutils/extend/ViewExtend.kt
[CSingleClick.kt]: cutils/src/main/java/com/carlos/cutils/aop
[CUncaughtExceptionHandler.kt]: cutils/src/main/java/com/carlos/cutils/execption

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.carlos.cutils.execption

import com.carlos.cutils.util.LogUtils
import kotlin.system.exitProcess

/**
* Created by Carlos on 2019-10-29.
*/
open class CUncaughtExceptionHandler : Thread.UncaughtExceptionHandler {

override fun uncaughtException(t: Thread?, e: Throwable?) {
if (t == null || e == null) return
LogUtils.d("find uncaught execption:", e)
quitApp()
}

private fun quitApp() {
android.os.Process.killProcess(android.os.Process.myPid())
exitProcess(1)
}

}
7 changes: 0 additions & 7 deletions cutils/src/main/java/com/carlos/cutils/util/TimerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,4 @@ class TimerHelper(private val spaceTime: Long, private val mTimeProcessor: TimeP
fun process()
}

fun abc() {
TimerHelper(100, object : TimeProcessor {
override fun process() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
}
}
14 changes: 14 additions & 0 deletions notes/execption/CUncaughtExceptionHandler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 全局捕获未捕获的异常类CUncaughtExceptionHandler.kt

## 适用场景
- 捕获未捕获的异常,做上报异常或APP异常处理操作。

## 提供方法
在Application里面全局注册
```
Thread.setDefaultUncaughtExceptionHandler(CUncaughtExceptionHandler())
```

|方法名|方法说明|
|:---|:---|
|uncaughtException|默认内部做了退出APP操作,可重载该方法实现自己的逻辑|
File renamed without changes.

0 comments on commit 2ea9dbe

Please sign in to comment.