if is not catching... nor does try-catch... #320
Replies: 7 comments
-
Posted at 2014-10-22 by @allObjects The if (C) {...}-thing still gives me annoying grieve,... I thought the added curly braces would have solved the issue for good...
Related to this code (line 10 in constructor), coming from the (again) working space-only-minified sandbox modules folder. (Had to re-enable some minification option after getting unexplicable out of memory error - see http://forum.espruino.com/comments/11900960/).
The constructor is invoked with undefined for C. The minification messes with the code to the point where the execution and block nesting becomes broken... Why would I say so: Adding/removing some code further down in the module made the error flip-flop... Interestingly, when I put a console.log() in the if-(then) block, it 'tricks' the minification and - miraculously (for me) - works:
@gordon, since you know your code like your own pockets, I'm sure you have a nice explanation - and may be - even a remedy top of your head... ;-) The stuff seems to be related to what @DaveNI experienced in Minified Code Producing Error - Solved at http://forum.espruino.com/conversations/257029/ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-23 by @gfwilliams So are you describing two different errors? The first issue happens with unminified code outside of a module? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-23 by @allObjects Yes, two different 'errors' - may be actually 3: The if-issue - covering a double issue - is now clear (I guess): it is the combination of minification and Espruino's interpreter and the 'common' JavaScript syntax and Espruino's interpreter. Latter could be fixed by adding curly braces, when then get removed by minification, because minification detects that there is only one statement in the block(s) and removes the curly braces, which get syntax and interpreter at odds again. The second one is the try-catch thing... it is somehow not working the way I'm used to... I expected it would catch this error: for loop can only iterate over .... and object's properties -and not over undefined object C. (try { var C = undefined; for (var v in C).... } catch(x) {.... }). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-25 by @gfwilliams Would it be ok if you posted some separate issues on GitHub, ideally with a simple section of code for each? I'm a bit busy right now with the new KickStarter so I don't want to forget about them - If they're on the issue tracker I'll be able to pick them up easily and fix them when I have a few minutes. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-25 by @allObjects @gordon, np, well understood... I'm excited about he Pico! Congrats: 2 days and 50%, trippled+ since I noticed yesterday! (of course, I'm 8 hrs time zone late...). Issue will not get forgotten... I will have to go back to that particular code anyway. In the meantime I did some work on ILI9341 module... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-26 by @gfwilliams Thanks! :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-29 by @gfwilliams Just to say I just fixed |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-10-21 by @allObjects
In handling of optional parameter in constructor I got a bit lost... and still am... ?-(
This is the original code, and I do not know what is wrong with it...
Running this code I get following console output:
I had expected that by design the if would have taken care of an undefined parameter variable C and skip the for-loop. The for-loop should only execute when is C defined.
Invoking constructor with empty object works:
logs:
Invoking constructor with changing object works:
logs:
Next step I tried was for loop with curly braces - to no avail:
Next step I tried if with curly braces - but not the for loop - and it worked... (update: ...hold your horses, this was not the last snag... keep on reading!)
Sure, I always recommend to use curly braces. Before I though added them, I tried the avenue of try-catch to find out what is going on. It seemed to me odd that the reporting of the error was actually after execution of all the code and the error did not stop the code from executing... (as it would have done in a browser).
logs:
Surprisingly, the try-catch does not catch the error... it lets the faulty expression to pass... so I wrapped the actually expression in the constructor into a try-catch block...
with the same puzzling result...
So I'm asking:
I had tried to use try-catch block in a different project,... and it did not work there either. Because int that project it was precaution and the anticipated possible error did not show (yet), so I ignored 'to go to the bottom of it'.
Beta Was this translation helpful? Give feedback.
All reactions