Catch runtime error / Identify the blocks that cause it

Hello, i wonder if some errors like "invalid text operation" can be catched by Screen.ErrorOcurred or other method.
I'm talking about aleatory errors from Clocks or Web.gotText that are working well during several days.

Forced Example: If i wrote a text with less than 2 chacarters in "Textbox z", "then i get an invalid text operation message"
image
image

I wonder if i can get a message like this:
image

Thanks in advance.

1 Like

This is because you want to show from a text with only one character or an empty textbox two characters

to avoid that check lenght of textbox

1 Like

I'm sorry @dora_paz but i think that you don't read my question. Is a "Forced Example"
And i am not talking about Companion, I am talking about a huge compiled .apk (more than thousand blocks).

Yes, you could write blocks to generate a notifier based upon the inputs you want to apply and the conditions required for those inputs

@TIMAI2 , thanks for answer.
That's not correct, because Screen.ErrorOcurred doesn't catch runtime errors that don't belong in this table:
https://www.professorcad.co.uk/appinventorerrormsgs

Please try my Forced Example adding the block below and see for yourself.
You will not see any message from the Notifier1
image
Regards.

1 Like

If the Original Post was a complaint about the lack of a stack trace to accompany AI2 error messages, I wholeheartedly agree.

Things not mentioned that would have made debugging easier:

  • block experiencing the error
  • procedure enclosing that block
  • Event enclosing the block or called procedure
  • Screen enclosing that event
4 Likes

Thanks @ABG, you described it very professionaly. Beyond calling it a complaint, I wanted to mention the topic in the forum because I did not find any query about it.
Maybe i can label TAIFUN, but i suppose that it is strictly forbidden.

Because you didn't include any blocks to capture the error and return this to "another" notifier.

It may be that what you want to do is change how AppInventor currently responds to runtime errors, which will mean (significant) changes to the app inventor sources. it may be possible to write an extension to intercept runtime errors as they occur, but then you would need responses for every eventuality.

The easiest solution is along the lines as suggested by @dora_paz, which is to capture the error before it occurs (e.g. incorrect entries/data/values). As a developer, one should be coding blocks to avoid runtime errors for the the end user....

2 Likes

@TIMAI2 I don't understand. What blocks i could include to capture the error if my runtime error is not catched by Screen.ErrorOcurred.

I'm not asking about how to prevent bad inputs, my runtime errors doesn't occurs with text strings, there was an example.
Maybe the correcto answer is "No, it si not posible".

This question is not about a specific error, is about how to catch runtime errors.
Regards.

you can't catch runtime errors, you have to think about how to avoid them...
for example before trying to select an item from a list make sure the list is long enough
or before trying to get a segment from a text, make sure the text is long enough, etc.

but I agree what @ABG said, see here

what is your opinion about this @ewpatton ?

btw. there is an extension, which might be able to help, see here
https://community.kodular.io/t/try-catch-extension-an-extension-to-code-with-try-and-catch/133467/10?u=taifun
and @dora_paz already asked there, if your example from post #1 could be catched using that extension, however up to now there was no answer from the extension author...

Taifun

1 Like

Can normal Java try{} catch(Exception){} catch runtime errors ?

I'm not talking about the extension.

Thank you, i try with this extensión.

And thanks @dora_paz for asking there.

1 Like

See for example the explanation here

Taifun

We have explored the possibility of implementing more robust debugging capabilities in App Inventor. However, none of the attempts to do so have obtained significant traction. If the resources become available to tackle this further I would be glad to do so.

1 Like

@ewpatton If there is a way to help, I will be pleased to do so.
Regards.

Author's answer:

https://community.kodular.io/t/try-catch-extension-an-extension-to-code-with-try-and-catch/133467/11

If thats the case, why not add a try catch block ?

(This might be like a control block, so I marked a control <span>.)

1 Like

Extension developer send me to test an update. Is this what you are looking for ..?

2 Likes

Now you can test latest version provided by developer

1 Like

(added to FAQ)