Android Question Answered: Can we catch unhandled exceptions?

Lee Gillie CCP

Active Member
Licensed User
Longtime User
My background is VB.NET. Here we can declare handlers for unhandled exceptions, and also thread exceptions. These two will pretty much catch ANYTHING that localized handlers do not. These are wonderful, especially for Windows Services to provide more info than the general system event log.

I'm not really a Java expert, but see it has a thread-level ability to declare uncaughtExceptionHandler and also a defaultUncaughtExceptionHandler. I have not yet experimented to see if I can trigger these from B4A reflection, or via Java Inline code. That seems like uncharted territory.

Has anyone been able to figure out how to implement really tight exception handling for B4A? By tight, I mean very low likelihood something will get lost? I know how to create localized try-catch blocks, but am looking to put something in place for exceptions that are not caught by localized handlers.

I am striving to create an exception capture routine that provides a screen dump, info about the app, configuration info, and a stack trace. I hope to also include recent LOGCAT captures. The routine ZIPs and uploads the files needed for QUICK problem diagnosis.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
I've been able to set UncaughtExceptionHandlers for threads I create in Java code and they work when run in B4A apps. B4A Threads (the main Thread as well as Threads created with the Threading library) are more problematic. I can set the handlers for those Threads but they don't seem to override B4A's handlers.

I think you should make a wish for a new feature that would allow you to plug-in a custom method into B4A's DefaultUncaughtExceptionHandler. I've seen a few other members trying (unsuccessfully) to implement something like this; I'm pretty sure they'd second this wish.
 
Upvote 0
Top