try/catch

Hi,

Can anyone tell me if I am missing something with this code ?

Why is the exception not caught?

System.println("BEGIN");
var numberArray = [0, 0, 0];

try
{
  System.println("a");
  numberArray[4] = 1; 
  System.println("b");
}

catch (exception) {
  System.println("catch");
}

finally
{
  System.println("finally");
}

System.println("END");

The similator output the following :

BEGIN
a

Error: Array Out Of Bounds Error
Details: Failed invoking <symbol>


Note : I have tested using SDK 3.0.10 and 3.0.12.

Thanks

  • ok thank you! ugh - frustrating.

  • yes, I understand you, well such ecosystem...

  • You can't catch null*2 - it's also Unhandled exception, no more code is executed

    I thought that was the case until recently; in fact I'm sure I tested and confirmed it a few months ago.

    But I recently found that you can in fact catch invalid type errors (such as null * 2). To be sure I've just re-run a test of exactly that to confirm that you can. At least in the simulator. Not sure if this is a change in behavior, or if I just messed up my testing previously...

  • Yes, you are right in case of null but when I tested it last time it was impossible to catch it.

    Unfortunately I can't catch many errors (properties/storage).

  • WOW Guess what! I caught the getValue() exceptions and avoided a crash. Check this out. It threw an exception for two of my User Settings... the two that I just recently changed the KEY name. Like I said, it works in the simulator. But would throw Unhandled Exceptions and crash. But this try/catch technique worked. At the last minute, I decided to put in some instrumentation to see if there were any exceptions. There were, but my data field worked perfectly. YES!

  • When ever I call Application.Properties.getValue() I always do it in a try/catch.  When building a new app. properties are usually one of the things I do later in development and change the default values for testing

    function readSetting(key,default) {
        var ret=null;
        try {
            ret=Application.Properties.getValue(key);
        } catch(e) {
            ret=default;
        }
        return ret;
    }

    for example...

  • I used getProperty() for years with zero issues. I switched to getValue() recently. Strange that this getValue() bug (when changing a KEY name, apparently been around a while) hasn't been addressed. But glad to have learned about try/catch and that is mitigates this issue. THANKS, EVERYONE.

  • It's not a bug.  getValue() is designed to throw an exception if a key isn't found. And a different exception if the data type is invalid.  To fix the key not found" exception, use setValue() to update the .set file

    getProperty() would just return null for an invalid key and there was no way to see why.

  • The KEY is properly defined in properties.xml.

    So you are saying we are seeing the exception because the KEY isn't found in the Storage repository, because the KEY name for the Property was changed? That makes sense, except I would expect the CIQ_LOG.YML to report "InvalidKeyException" not the Unhandled Exception that is does report.

    Thanks!

  • Storage and Properties are two different things.  That was never clear with the old getProperty()/setProperty() as the same calls were used for both.  If there was a property defined it was in the .set file (settings), and if not, the .str file (the object store).

    With getValue/setValue where things are stored is based on Application or Storage.  For Properties, the .set file is used in the settings folder, but in storage, there is an idx,imt and .dat file in the data folder and not an str file