-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CUncaughtExceptionHandler class.
- Loading branch information
Showing
6 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
cutils/src/main/java/com/carlos/cutils/execption/CUncaughtExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.