Android Question Try to catch exception for javascript CallSub

hung

Active Member
Licensed User
Longtime User
In b4a,
b4a code:
...
wve.addJavascriptInterface(wv_home, "b4a")
...
Sub test1 (argp1 As String, argp2 As String, argp3 As String)

End Sub

In html loaded into webview,
javascript:
...
<button onclick='b4a.CallSub("test1", true, "p1", "p2", "p3");'>cmd01</button>
<button onclick='b4a.CallSub("test1", true, "p1");'>cmd02</button>
...

Obviously, button "cmd01" runs well but button "cmd02" crashes my app.

Question is: how do I capture the exception in b4a when "cmd02" CallSub, so I could stop my app from drop dead?
 

DonManfred

Expert
Licensed User
Longtime User
your amount of parameters does not match.
in cmd01 you have 5 parameters
in cmd2 3. This is the maximum allowed parameters.

See
Here you can see all possible variants you can use.
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
Sorry, that is not my question.

In b4a, I defined a sub "test1" with 3 parameters so the javascript in html in my webview can do b4a.CallSub("test1", True, "p1", "p2","p3").

It is ok to call with 3 parameters. But as the html is dynamically generated and there will be mistakes so it may call with less than 3 parameters.
e.g. it calls with one parameter then crash the app.

I don't want the app to crash but instead prompt warning. Is there any way?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I can not answer this. I do not use javascript, do not use webviews and do not wrote the library.

See the page linked: you CAN use one parameter.
one, two or three parameters are possible.

Maybe wait for someone who is familar with javascript and the javascriptinterface.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…