惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
U
Unit 42
Y
Y Combinator Blog
I
InfoQ
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
量子位
Microsoft Security Blog
Microsoft Security Blog
B
Blog
The Cloudflare Blog
F
Fortinet All Blogs
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
C
Check Point Blog
S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
T
Tailwind CSS Blog

ashishb.net

A day in Luxembourg - the richest country in the world I was asked to install malware during a fake interview Book summary: Breakneck - China's quest to engineer the future by Dan Wang Book summary: How to Teach Your Baby to Read Book Summary: The Discontented Little Baby Book by Pamela Douglas Introducing Amazing Sandbox - run third-party tools and AI agents securely on your machine Why software outsourcing gets a bad reputation? Book summary: The Natural Baby Sleep Solution by Polly Moore A day in Antwerp, Belgium Journey of online influencers Two days in Brussels, Belgium Shortcuts - when we love them and when we don't A visit to Rakhigarhi Three days in overhyped Paris Empty Japan, crowded Tokyo The real lock-in in GitHub is not the code, but the stars 11-day Norwegian Breakaway East Caribbean cruise Sanskrit and Sri Lankan Air Force Use REST with Open API The Achilles heel of American capitalism Costa Rica in 4 days At a juice stall in Sri Lanka A short stay at Warsaw, Poland Best practices for using Python & uv inside Docker Two days in Vilnius, Lithuania How IntelliJ IDEs waste disk space Pregnancy Why there aren't many digital nomads from India Two days in Riga, Latvia To keep your machine secure, run third-party tools inside Docker
Android uncaught exception handler and ANR
Ashish Bhatia · 2022-09-11 · via ashishb.net

While trying to install a custom exception handler to catch uncaught exceptions (crashes), I ended up writing

1
2
CustomExceptionHandler handler = new CustomExceptionHandler(Thread.currentThread().getUncaughtExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(handler);

instead of

1
2
3
Thread.UncaughtExceptionHandler existingHandler = Thread.getDefaultUncaughtExceptionHandler();
CustomExceptionHandler handler = new CustomExceptionHandler(existingHandler);
Thread.setDefaultUncaughtExceptionHandler(handler);

The difference looks minor but it broke the exception handler and converted every crash into a cryptic ANR!

1
2
3
4
5
6
7
0 libc.so syscall
1 libart.so art::ConditionVariable::WaitHoldingLocks(art::Thread*)
2 libart.so art::ThreadList::WaitForOtherNonDaemonThreadsToExit(bool)
3 libart.so art::JII::DestroyJavaVM(_JavaVM*)
4 libandroid_runtime.so android::AndroidRuntime::start(char const*, android::Vector const&, bool)
5 app_process64 main
6 libc.so __libc_init

Very occasionally, I got a more useful error that didn’t look related but it was.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
java.lang.StackOverflowError:
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:20)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1068)
      at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java:1063)
      at net.ashishb.androidmusicplayer.util.CustomExceptionHandler.uncaughtException (CustomExceptionHandler.java:22)
      at org.chromium.base.JavaExceptionReporter.uncaughtException (chromium-Monochrome.aab-stable-484407323:6)