What's more efficient, checking for bluetooth connectivity or doing try/catch?

Hello,

I have found an error in my watch face and I am trying to figure what it is and the most efficient way to handle it.  If I restart my watch (Venu 2) without bluetooth, the watch face I have that uses complications and displays weather, crashes.  So, my assumption (yes, I know) is that when the watch starts without bluetooth and the complication tries to read the weather, the watch face crashes.  I thought by using the code:

            wxComp = Complications.getComplication(wxId);
            if (wxComp != null) {
                Complications.subscribeToUpdates(wxId);
            }

I'd handle it, but apparently not.

So, should I try a try/catch or system check for BLE connection every time?  Or, is there a better way?

Thanks

  • I checked for null returns in the complications.value.  If null, I requested the info old school style (except for temp which I defined as -99).

  • Consider this:

    			 if(ty==Complications.COMPLICATION_TYPE_CURRENT_WEATHER) {
    			    compWeather=complicationId.complicationId;		
    				Complications.subscribeToUpdates(compWeather);
                	Complications.registerComplicationChangeCallback(method(:compChanged));
                }

    Then in compChanged:

    	function compChanged(id) {
    		if(id.equals(compWeather)) {
                try {
                    wdata=Complications.getComplication(id).value;
                } catch(e) {
                    wdata=null;
                }
    		}
    	}

    I subscribe. but also register for a callback when the data changes.  Which on Android is about every 20 minutes

  • So, you'd recommend the try/catch over the if statement? And, null would throw an error with all complications? I know each complication value returns a specific type of information, but I didn't expect 'null' to cause an error to be caught.