Android Question Application_Error does not fire in resumable subs

Blueforcer

Well-Known Member
Licensed User
Longtime User
It took me hours to figure it out:
Application_Error does not fire in resumable subs

Test:
B4X:
Private Sub Button1_Click
    Wait For (crash) Complete (success As Boolean)
End Sub

Sub crash As ResumableSub
    Sleep(5000)
    Dim i As Int = "kjhlkJ"
    Return True
End Sub

I found a 4 years old post from Erel. I guess he forgot to fix it.
Is there a workaround or when we can expect a fix?



i tried to implement my own UncaughtExceptionHandler wich fires the handlecrash event even in resumable subs, unfortunally im unable to show any gui object like a msgbox in my handlecrash sub (wich works in Application_Error).
i assume the looper of the UI thread crashed

B4X:
#If Java
import java.lang.Thread;
import java.lang.Thread.UncaughtExceptionHandler;
import anywheresoftware.b4a.BA;

public static void setExceptionHandler() {
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            String message = e.getMessage();
            String stack = android.util.Log.getStackTraceString(e);
                BA ba = processBA;
                if (ba.subExists("handlecrash")) {
                    android.util.Log.e("CrashHandler", "UncaughtException ausgelöst");
                    android.util.Log.e("CrashHandler", "Fehlermeldung: " + message);
                      ba.raiseEvent(this, "handlecrash",message, stack);
                }
        }
    });
}
#End If


Any ideas?
Cheers
 
Last edited:

Blueforcer

Well-Known Member
Licensed User
Longtime User
As one workaround i managed to start a new activity. This is fine for my purpose.
You can also start another app

B4X:
#If Java
import java.lang.Thread;
import java.lang.Thread.UncaughtExceptionHandler;
import android.content.Intent;
import anywheresoftware.b4a.BA;

public static void setExceptionHandler() {
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            String message = e.getMessage();
            String stack = android.util.Log.getStackTraceString(e);

            Intent i = new Intent(BA.applicationContext, de.dinotec.netplus.crashreporter.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra("msg", message);
            i.putExtra("stack", stack);
            BA.applicationContext.startActivity(i);

            System.exit(1);
        }
    });
}
#End If

Crashreporter Activity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim Intent_ As Intent = Activity.GetStartingIntent
    Dim msg As String =Intent_.GetExtra("msg")
    Dim stack As String = Intent_.GetExtra("stack")
end sub
 
Last edited:
Upvote 0
Top