Created
February 7, 2022 12:45
-
-
Save LouisShark/d10831007c10a0d263d5779ff5204b82 to your computer and use it in GitHub Desktop.
托管Looper可以catch一些报错但不影响业务的exception
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
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