I'm testing some things and have a piece of inline java that is throwing an exception under some conditions. That exception is not fatal for the app at all, and is also wrapped in a try/catch block.
However, if the exception is thrown, it's not possible to live update the code anymore. In fact, one needs to even clean the project to get it running as expected again.
I can't tell if this is a bug, a known limitation or simply an error on my part somewhere. I'm hoping for the latter, and for the forum to help me out.
This is my code. (Stripped down to bare minimum.)
A tap on the button produces this in the log...
...which seems to be working perfectly fine. The exception message is in there. Multiple taps just produces the same over and over again.
However, any code changes in the myButton_Click sub changes things completely - even if the change is totally harmless. (It seems to be fine to change other subs though.) To try this, change the log message "Clicked" to "Clicked2" and save to update the code running in the phone.
Tap the button, and this is the result:
However, if the exception is thrown, it's not possible to live update the code anymore. In fact, one needs to even clean the project to get it running as expected again.
I can't tell if this is a bug, a known limitation or simply an error on my part somewhere. I'm hoping for the latter, and for the forum to help me out.
This is my code. (Stripped down to bare minimum.)
B4X:
Sub Globals
Dim myButton As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
myButton.Initialize("myButton")
myButton.Text = "Throw exception"
Activity.AddView(myButton, 5%X, 30%Y,90%X,20%Y)
End Sub
Sub myButton_Click
Log("Clicked")
Try
Dim JO As JavaObject = Me
JO.RunMethod("justTestingStuff", Null) ' <-- This is line 44
Catch
Log(LastException)
Return
End Try
LogColor("Everything seems to have worked out fine.", Colors.Green)
End Sub
#if JAVA
public static void justTestingStuff() {
throw new RuntimeException("Stuff went bad");
}
#End If
A tap on the button produces this in the log...
B4X:
Clicked
(RuntimeException) java.lang.RuntimeException: Stuff went bad
...which seems to be working perfectly fine. The exception message is in there. Multiple taps just produces the same over and over again.
However, any code changes in the myButton_Click sub changes things completely - even if the change is totally harmless. (It seems to be fine to change other subs though.) To try this, change the log message "Clicked" to "Clicked2" and save to update the code running in the phone.
Tap the button, and this is the result:
B4X:
Clicked2
Error occurred on line: 44 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:778)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:358)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: Stuff went bad
at b4a.example.main.justTestingStuff(main.java:457)
... 20 more
(Exception) java.lang.Exception: java.lang.reflect.InvocationTargetException