0
Answered

try catch doesn't always work

rocfusion 6 years ago in iRidium Script / AV and Driver scripts updated by Oksana (expert) 6 years ago 4
Hi,

I have a script that parses an object.  Not every record contains the same fields. 

Only through breaking some other code in another script did the try catch statement trigger and the error was shown.

This is an simplified example of what I was trying. 

myobject =  [{ test : [data:"123",data:"1234"], test2:"abcd"}, { test : [data:"13",data:"134"], test2:"abc"},
      {  test2:"abcd"}];

try {
for(i=0;i<myobject.length;i++)
  for(y=0;y<test.length;y++)
    IR.Log("y is "+y)
}catch(error){IR.Log("there was an error  "+error)

I think that when you try this as a stand alone script its fine, yet when this example is used in an more complex project that contains multiple drivers then the try catch become less reliable.  My project contains  KNX, SIP, SONOS, XBMC,  Global cache, denon; plus more.


Thanks,


Roger
Hi Roger!

The error in the Log is a string from IR.Log method

IR.Log("there was an error  " + error)

if change this line then  error not will show:
IR.Log("there was an error  ")
Hi,

Will this still tell  me where the code is broken?

Thanks,


Roger
Hi Roger, yes.

The script error showed message is information message, not message of breaking the code in Console Log.

there was an error  ReferenceError: C:\Users\Sergey\Documents\iRidium mobile 2\Settings\iRidium\Main\te.js:5: test - It is message from error variable