Android Tutorial Uncaught Exceptions

hibrid0

Active Member
Licensed User
Longtime User
I test it on my small project and is too useful!!!
Thanks Erel.
Anyware software is a great developer team.
 
Last edited:

PhilipBrown

Active Member
Licensed User
Longtime User
Can anyone verify that the following statement is correct for version 5.5 of B4A?

If a runtime error occurs outside a Try-Catch block, what the user sees will depend on how you have distributed the app and whether the error is caught internally.
If you distribute via Google Play and your application raises an error which is not caught internally, the user will be asked to send a crash report. This happens automatically. If the user agrees to send the report, you can see the result in Google Play Developer Console.
If you distribute your application directly with an apk file and your application raises an error which is not caught internally, the user will see an error crash report as described below.
The same error report is shown when your application raises an error which is outside a Try-Catch block but is nevertheless caught internally, no matter how you have distributed it.
The user sees an error crash report which asks if they wish to continue.​
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you haven't added the application_error sub to the starter service then the behavior will be exactly as in previous versions (which means that in most cases the user will see the "Continue? yes no" dialog).

This new feature allows you to handle the crash yourself.
If you return True from Application_Error then the default crash handler will be executed.
In the case of a Google Play app then the user will be asked to send the crash report.

How you handle the crash is up to you. It will not show anything "special" unless you implement it, as in this example.
 

Tan

Member
Licensed User
Longtime User
Hi,

is it in any way possible to show a dialog in "application_error" (e.g. a msgbox... ask the user, if he want's to send a crash report via email)?

If I try that, I get the following exception:
"android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application"

Even if I return False, the Activity seems (in that moment) to be in the process of finishing!?! Any other way of showing a dialog?

Best regards
Tan
 

Blue.Sky

Active Member
Licensed User
Longtime User
Hi Erel.
This property in b4a is good
I download your sample and run it
When i press button,app force stop and show email intent
Can i prevent stop app with this property?
 

Blue.Sky

Active Member
Licensed User
Longtime User
Hi Erel.
This property in b4a is good
I download your sample and run it
When i press button,app force stop and show email intent
Can i prevent stop app with this property?
It solved.return false in Application_Error for prevent close or stop app
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel why you dont add the sub of error on the Main activity already?
why need a service?
B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
   Return True
End Sub

and the starter service i need to execute this or its automatic?
B4X:
StartService(Starter)
on activity create?
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
Nice, and its possible send the email automatic? or only with user click?
 

MMORETTI964

Member
Licensed User
Longtime User
I'm trying to use this exception to handle errors occurred (in a big project) when Android choose to free memory (and your program was in background for a long time).
When you resume the app sometimes (depends on the memory, AFAIK) your application start with errors (due to images or control not more existant).
As I seen by some heavy-heavy programs (Ex: Magic 2015), when you restore from background the programs (sometimes) magically "restart".
I think there is some systems to trap these kind of "untrappable" errors and restart programmatically the application.
Do you think the approach to these kind of error with the uncaught-excpetions is correct?
Can I restart the application without any kind of system message like "... is terminated" (I should substitute with a message of my own) when I have an exception uncaughted?
I should use a newly created activity to make that (Exit application, message and restart)?
Thank you in advance.
Maurizio
 

MMORETTI964

Member
Licensed User
Longtime User
This is a bug in your code. Please start a new thread for this question for further discussion.
I will, but just for knowing...
Can I restart the application without any kind of system message (I should substitute with a message of my own) when I have an exception uncaughted?
I should use a newly created activity to make that (Exit application, message and restart)?
 

MMORETTI964

Member
Licensed User
Longtime User
You can use StartServiceAt to schedule your app to start and then call ExitApplication to kill the process (not that I recommend this approach).

Can I use ExitApplication inside the Application_Error sub?
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel.
I have to implement "Uncaught Exceptions" within an old project that doesn't have the Starter Service.

I have a question about this: Can I implement the Starter Service (mandatory for the "Uncaught Exceptions" implementation) within my old project without impact the previous (core) App code and the main App behavior ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…