Issue with Handling Bluetooth Pairing Errors

Hey, this is my first post related to MIT App Inventor.

I'm having trouble handling errors when pairing via Bluetooth. I created an app that connects to an ESP32 via Bluetooth, but I ran into an issue:

If I select a device from the list of paired devices, but it's unavailable (turned off or out of range), Android returns an application error and expects it to close (even though the app is still running). I tried adding error handling—redirecting the user to another screen in case of an issue—but the app still crashes.

Does anyone know how to properly catch this error and prevent the app from crashing? Thanks in advance!

This sounds like you get a runtime error.... you can't catch runtime errors...
What is the manufacturer and Android version of your device? What happens on another device?
You might want to provide a screenshot of the error message

Taifun

I have tried on various versions of Android, both the latest and older ones, and on different phone brands such as Samsung, Xiaomi, and Ulefone.

nie odpowiada – it either freezes, waits, or closes.

esp32 not responding

Close application

Wait

Unfortunately I do not have more ideas ... probably someone else?
Taifun

Dear @Krystian_Szymanski ,
please have a look to this post:

You'll find therein a couple of codes (app and ino) that were working for me. Probably they can help.

Hey, thanks for your response, but my issue is a bit different. If the device is nearby, I have no problem pairing with it. The problem occurs when the device I am paired with is not available (for example, if it has been disconnected from power).

OK, I've understood, now.
First of all, please note that the BlueTooth Error block is discontinued and it is suggested to use the ScreenX error block, instead (as you do).
What you are describing is effectively pretty weird, because when one tries to connect a non available BT address, the app doesn't crash: it simply cannot connect.
The picture here below shows how I normally try to connect a BT transmitter (an Arduino, and ELM327, others...).
You can see that the "1" is the BT address that I retrieve from a file (instead of using a list picker, I strore the BT addresses of my BT devices into a txt file).
If the connection with the "primary" BT address fails, I try with a secondary one, indicated in point "2" of the picture.


If also the secondary fails, I exit the app.
In neither cases (1 and 2) the BT error popup isn't raised and, most important, the app isn't blocked,
Please try to adapt my example to your needs and verify if it helps.
Best wishes.