Unhandled Exception on Fenix 8 47mm - How to handle it correctly?

Hi,

I have a user with a Fenix 8 47mm who has been using my watch face for a few years but has suddenly had Unhandled Exception errors. The stack dump that come from the CIQ_LOG.YML file points to a block of code that is all inside a try-catch block. Are there some other errors I am not handling? Any ideas on how to debug or troubleshoot this?

Thanks

Error: Unhandled Exception
Time: 2026-03-22T21:12:17Z
Part-Number: 006-B4536-00
Firmware-Version: '21.39'
Language-Code: eng
ConnectIQ-API-Version: 6.0.0
ConnectIQ-Version: 5.2.0
Store-Id: d29b3a19-2b35-40be-9f65-f069fb8f86ed
Store-Version: 136
Filename: G3K04159
Appname: GMT 4 Master II
Stack: 
  - pc: 0x10003a2e
  - pc: 0x100050f6

  • How does the code block where the unhandled exception occurs look?

  • function getPressure(pressureUnits) {
    	try {
    		var freeMem = Sys.getSystemStats().freeMemory.toNumber();
    		var senIterator = null;
    		var senHistory = null;
    		var senSample = null;
    		var senValue = 0;
    		pInd = " ";		// global to show pressure going up/down/steady
    
    		if (freeMem > 1000) {
    			if (Toybox.SensorHistory has :getPressureHistory) {
    === error ==>	senIterator = new Lang.Method(Toybox.SensorHistory, :getPressureHistory);
    				senHistory = (senIterator == null) ? null : senIterator.invoke({:order=>SensorHistory.ORDER_NEWEST_FIRST});
    				senSample = (senHistory == null) ? null : senHistory.next();
    				senValue = (senSample == null) ? 0 : (senSample.data == null) ? 0 : senSample.data;
    				var nowMin4 = new Time.Moment(Time.today().value());
    				var fourHours = new Time.Duration(-4 * Greg.SECONDS_PER_HOUR);
    				nowMin4 = nowMin4.add(fourHours);					
    				senSample = senHistory.next();
    				while (senSample != null) {
    					if (senSample has :data and senSample has :when) {
    						if (senSample.when == null
    						or  senSample.data == null) {
    							break;
    						}
    						if (senSample.when.greaterThan(nowMin4)) {
    							if (senSample.data > senValue) {
    								pInd = "+";
    								break;
    							} else if (senSample.data < senValue) {
    								pInd = "-";
    								break;
    							} else if (senSample.data == senValue) {
    								pInd = "=";
    							}
    
    							senSample = senHistory.next();
    						} else {
    							break; // exit loop if history more than 4 hours old
    						} // end if history is from last 4 hours
    					}
    
    					break; // exit loop if senSample does not have data or time
    				} // while loop
    			} // end if SensorHistory as getPressureHistory - some devices have SensorHistory but not all methods.
    		} // end device has enough memory to do fetch
    		senValue = checkRange(senValue, 95000.0, 105000.0);
    		return (pressureUnits == Sys.UNIT_METRIC) ? senValue.toFloat()/100.00 : senValue.toFloat()*0.0002952;
    	}catch (ex) {
    		return 0;
    	}
    } // end getPressure
    

  • Yep, I saw that one. Unfortunately no one replied to that with a meaningful answer! Your example is even harder to understand why it has not been caught.