+5
Voting

throwing custom errors with line numbers

r riksma 10 years ago in iRidium Script / AV and Driver scripts updated by Oksana (expert) 9 years ago 5
It would be nice if I could show a line number when I throw an error in my own code.

for example, if I run this piece of code:

  try {
    if (typeof currentStyle[options.name] == 'undefined') {throw new Error("Unknown style name: " + options.name);}
    }
    catch (err) {
        throw new Error(err.lineNumber + " " + err.message);
    }


the following line is logged:

02-12-2015    13:28:03    Kernel.Info    192.168.253.102    [12-02-2015 13:28:04.000]  WARNING  Script exception: Error: undefined Unknown style name: menuLogo


When an Error is logged from iridium itself it looks like this:

02-12-2015    13:31:42    Kernel.Info    192.168.253.102    [12-02-2015 13:31:43.000]  WARNING  Script exception: ReferenceError: /var/mobile/Containers/Data/Application/0CE95966-BFE3-4352-B1E9-F38E3EB8963C/Library/Caches/iRidiumMobile/EveryDevice/ViewLibrary.js:185: erraaa


How can I get the file and line number as well?
It would be great if you could always show this information in the log if the Error is not caught.
Hi, rriksma!

iRidium SEE JavaScript can return only two property (message and name) of an Error object. For example:

IR.Log(err.message);
IR.Log(err.name);

You can not get line number with creating a error manualy by: "throw new Error". But if error generated by app then you can convert error object in "catch" to the string and to parse line number with RegEx

For example:
SyntaxError: C:\Users\Sergey\Documents\iRidium mobile 2\Settings\iRidium\Main\test.js:6:
Hi Sergey,

Thanks for your reply.
Would it be possible to request this to be added as a feature then?
I think it would be very helpful for debugging purposes if you could generate a stack trace of some sorts, and then maybe even sending it by email if it is uncaught.
If you only know the message of the error and not where it is thrown it might be very difficult to find the cause.

If this is really not possible, what do you think is the best way of generating an error in Iridium itself?
I'm thinking of referencing null on purpose but maybe you have a better idea.
Hi, rriksma!

Thank you for your idea. It is available for voting for now. The more votes it gets the sooner it will be implemented.