As I developed my new Android application, Vault 3 for Android, I found it very convenient to catch and log uncaught exceptions. Here's how you can catch them in your app.
Step 1: Create a class inherited from UncaughtExceptionHandler, and implement the uncaughtException method:
public class CustomUncaughtExceptionHandler implements UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable tr) {
String logMessage = String.format("CustomUncaughtExceptionHandler.uncaughtException: Thread %d Message %s", thread.getId(), tr.getMessage());
Log.e(StringLiterals.LogTag, logMessage);
tr.printStackTrace();
if (VaultPreferenceActivity.isUncaughtExceptionLoggingEnabled()) {
PrintWriter printWriter = null;
try {
printWriter = new PrintWriter(new FileWriter("/sdcard/Vault3Log.txt", true));
logMessage = String.format("%s\r\n\r\nThread: %d\r\n\r\nMessage:\r\n\r\n%s\r\n\r\nStack Trace:\r\n\r\n%s",
new Date(),
thread.getId(),
tr.getMessage(),
Log.getStackTraceString(tr));
printWriter.print(logMessage);
printWriter.print("\n\n---------------------------------------------------------------------------\n\n");
}
catch (Throwable tr2) {
}
finally {
if (printWriter != null) {
printWriter.close();
}
}
}
}
Step 2: Call Thread.setDefaultUncaughtExceptionHandler with your UncaughtExceptionHandler-derived object early in the application lifespan.
Thread.setDefaultUncaughtExceptionHandler(new CustomUncaughtExceptionHandler());
Since I want to start catching uncaught exceptions as early as possible in my app's lifespan, I implemented a custom Application class for Vault 3 for Android:
public class VaultApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new CustomUncaughtExceptionHandler());
Log.i(StringLiterals.LogTag, "VaultApplication.onCreate");
}
...
This application class is specified in my AndroidManifest.xml file:
...
<application
android:name="com.ericbt.Vault3.VaultApplication"
...
If you need to keep track of important notes, with optional strong encryption, check out Vault 3 for Android. Thanks!
| Title | Date |
| Node.js + Express: How to Block Requests by User-Agent Headers | January 7, 2026 |
| Vault 3 is Now Available for Windows on ARM Machines! | December 13, 2025 |
| Vault 3: How to Include Outline Text in Exported Photos | October 26, 2025 |
| .NET Public-Key (Asymmetric) Cryptography Demo | July 20, 2025 |
| Raspberry Pi 3B+ Photo Frame | June 17, 2025 |
| EBTCalc (Android) Version 1.53 is now available | May 19, 2024 |
| Vault 3 Security Enhancements | October 24, 2023 |