One more puzzling (to me) Unhandled Exception

Ok, so this line of code is from the method of a makeWebRequest running in the background process (from onTemporalEvent) and it generates a Unhandled Exception for someone (one watch model, 44 times).

timestamp = timestamp + "|" + Application.loadResource(Rez.Strings.label_launch_widget);

label_launch_widget is defined like this

<string id="label_launch_widget" scope="background">Launch widget</string>

timestamp is set from this try/catch code and it isn't touched until that line above that asserts

var timestamp;
try {
    var clock_time = System.getClockTime();
    var hours = clock_time.hour;
    var minutes = clock_time.min.format("%02d");
    var suffix = "";
    if (System.getDeviceSettings().is24Hour == false) {
        suffix = "am";
        if (hours == 0) {
            hours = 12;
        }
        else if (hours > 12) {
            suffix = "pm";
            hours -= 12;
        }
    }

    timestamp = " @ " + hours + ":" + minutes + suffix;
}
catch (e) {
    timestamp = "";
}

So timestamp is either an empty string (not null) or a time of day string.

Both the label and the timestamp is used elsewhere, and even there without any issue on my watch and simulator, so why can it create an Unhandled Exception? Could it be because of the watch model? It's a DescentTm Mk2 S: V8.70 according to ERA. Watch language is in Korean according to ERA but it's not in the resource files, so I'm assuming it defaults to English?

  • How confident can we be that ERA reliable and isn't reporting bogus crash like the one above or this one:

    https://forums.garmin.com/developer/connect-iq/f/discussion/330905/do-you-see-why-this-code-generate-an-unhandled-exception/1608313#1608313

    Or many other 'crash' returned that do not make sense. I just checked my watch and I use daily the applications I maintain and yet, not a single entry in the crash log since the latest version where uploaded to ConnectIQ.

    Here's another one:

    "File not found" error! What? Ok, so the line that it supposedly crash at is

    weather = Storage.getValue("OpenWeatherMapCurrent");

    Ok, so maybe that key isn't created, which could make sense, except the doc doesn't mention this error and null can be returned. I renamed that specific line to OpenWeatherMapCurrent1, which doesn't exist. Emulator didn't bark, it just set weather to null. So why this error eight times in ERA??? Like I said, how confident can we be that ERA is reliable and isn't reporting bogus crash?

  • An ERA is based on the ciq_log file from a user device and none are "bogus".  While there can be a system error that causes the crash, like your "file not found".  That's not a bogus ERA, just one you can't to anything about except let Garmin know.

    Understand with the sim, you only see WW devices and even then, your settings may be different than the user settings for things and that may cause a crash.

    Also, with an ERA, if you see "7 occurrences", that can be the same user 7 times if they are all the same language.

  • Well, I have a lot to let Garmin know then, because there are many. Like the first post of this thread, because I have no idea how a Unhandled Exception could be thrown there. Or the one I linked in my last post.

  • As your first example is using a try/catch, the error you are seeing ("unhandled exception") likely isn't from the code you posted.  In ERA you should see a simple stack trace, with file names and line numbers.  What do you see? The line number can be off a couple of lines but should point you very close.

  • Since it's the method of a webrequest, there is nothing in the stack the filename and line number, which points to the label_launch_widget below. Lines around it is no help either

       timestamp = timestamp + "|";
    }
    else if (responseCode == 401) {
       timestamp = timestamp + "|" + Application.loadResource(Rez.Strings.label_launch_widget);
    }
    else if (responseCode == 408) {
       timestamp = timestamp + "|" + Application.loadResource(Rez.Strings.label_asleep);

  • Is it the exact same source you used when you build the iq file for the store?  So which line is shown in the stack trace?  

  • Yes, I went back to the branch created for the release.

    This is the whole ERA report

    Error Name: Unhandled Exception
    Occurrences: 182
    First Occurrence: 2023-04-20
    Last Occurrence: 2023-04-24
    Devices:
        DescentTm Mk2 S: 8.70
    App Versions: 7.11.5
    Languages: kor
    Backtrace:
        ServiceDelegate.onReceiveVehicleData:152

    Like I mentioned in the first post, could it be because it's in Korean? I don't have a Korean translation file, just English, French, Dutch and Sweden.Usually it defaults to English. Maybe different for Asian languages?

  • I tried in the Simulator with Korean selected as Language and a Descent Mk2 S as a watch and as expected, English was the running language. No crash either.