Nested catch and throw do not seem to work properly #447
Replies: 7 comments
-
Posted at 2015-08-26 by @gfwilliams Hmm, I don't think you're doing anything wrong. That looks like a bug to me... For instance this will work:
I'll make sure I put that in the bug tracker. To be honest I don't think people generally use exceptions much with Espruino, so it probably hasn't come up before. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-26 by asez73 Ok, thanks! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-26 by @gfwilliams Not sure I understand? I'd definitely be interested to see some speed figures - I didn't consider exceptions to be faster than 'normal' code. I've fixed the problem now anyway - it should be fixed in this build when it's done, so the 1v81 release. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-26 by @allObjects 'Faster'... may be due to the fact that with 'logically massive' use of exceptions overall code code size is smaller and with less code to run it is faster. Elimination of if/then/else and returning and distinction of error/exception codes (on top of application codes) slims code to implementaton of the good path and reduces issues handling code to a minimum and only in the (call hierarchy stack/) layer where of interest. @asez73, as a practitioner of exception paradigm you'd like to share your rational. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-27 by asez73 Hi @gordon and @allObjects In fact it started with the GPS module and trying to get more than randomly precise altitudes, latitudes and longitudes. So that implied to handle more than the RMC and GGA which provides just not enough figures to have a correct understanding of the GPS receiver position. For instance GPGBS provides the position's errors. By the end, I added checksum control of sentences and a better sentence delimitation, serial bauds were raised to 115200 too. Now, for instance, the lines below takes 0.01681646164 s per line. But those are empty lines with just the time fix.
And once the fix is done, since there is more data to be extracted out of the received sentences, you have a mean time per line of 0.02384059895 s. This figure had gone up to 45 ms in the if/then code structure. All of those little variations, around normally received sentences, added some split/pop/if code and beeing applied at every line received, could end up to be run 13 times per second. An other optimisation will be to shut ON or OFF some NMEA sequences once thay have provided the desired data and until this data has to be refreshed: date from GPSZDA is such a case.
Now I still have to figure out a minimal cost to the handling of the reactions of the application to changes in this data stream. I am thinking about using gps.emit('TimeFix') and other event driven approaches like that. It would clearly separate the application from the receivers status and data. Definitly, I am not considering any coding approach but for its real results and efficiency. We are using mcus not linux. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-27 by @gfwilliams That's great - thanks for all those details - really interesting to know, and to see some code that you've been doing time tests on. Are you running with your code as-is, or minified? And does everything work for you with the new build? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-27 by asez73 @gordon, It runs as is on 1v80.280 so far. I will try the new build today. I used a timing approach fairly basic as below:
mychrono is then called at proper places in the gps loop. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-26 by asez73
Hello All,
The following code is attempting to generate a catched error inside the 'inner' function and rethrow it to the 'outer' function so that it is catched again there.
Testing it on JSFiddle does produce the 2 Catch inner and outer to happen, it is not the case on Espruino 1v80.
Am I missing something?
There are 2 threads on this forum about catch and throw but they did not helped me...
Thank's for reading.
Beta Was this translation helpful? Give feedback.
All reactions