Skip to content

Instantly share code, notes, and snippets.

@LouisShark
Created February 7, 2022 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LouisShark/d10831007c10a0d263d5779ff5204b82 to your computer and use it in GitHub Desktop.
Save LouisShark/d10831007c10a0d263d5779ff5204b82 to your computer and use it in GitHub Desktop.
托管Looper可以catch一些报错但不影响业务的exception
import android.os.Looper
import android.util.Log
fun looper() {
Gloal.handler.post {
while (true) {
try {
Looper.loop()
} catch (e: Throwable) {
val stack = Log.getStackTraceString(e)
if (e is SecurityException) {
Timber.w(e)
} else if (
stack.contains("SelectionHandleView")
|| stack.contains("Magifier.show")
|| stack.contains("Toast")
) {
Timber.w(e)
} else {
throw e
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment