-
• #2
Some more suspicious things...
This behaves as expected:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); const arr= new Uint32Array([1,2,3,4]); console.log('-A1-'); if (!!arr.xyz) console.log('-A2-'); console.log('-A3-');
But this
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); const arr= new Uint32Array([1,2,3,4]); console.log('-B1-'); try{ if (!!arr.xyz) console.log('-B2-'); console.log('-B3-'); } catch(e){ console.log('-B4-',e); } console.log('-B5-');
reports some strange error (see 2nd UNCAUGHTEXCEPTION message):
-B1- !!!UNCAUGHTEXCEPTION!!! Error { "msg": "Field or method \"xyz\" does not already exist, and can't create it on Uint32Array", "type": "Error", "stack": " at line 2 col 12\n if (!!arr.xyz) console.log('-B2-');\n ^\n" } !!!UNCAUGHTEXCEPTION!!! SyntaxError { "msg": "Got catch expected EOF", "type": "SyntaxError", "stack": " at line 1 col 1\ncatch(e){\n^\n" } -B5-
Maybe another topic relates to this: i think that exceptions got lost without any notice when they occured inside a switch statement. i try to come up with some test code for this, too...
-
• #3
ok, as promised some sample code to reproduce the second problem when throwing inside a switch statement.
without switch(), everything behaves as expected:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); /* expect output === achieved output: -D0- -D1- CATCHED ... "simulate crash" -D8- -D9- */ function test( crit){ try{ const arr= new Uint32Array([1,2,3,4]); console.log('-D1-'); if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz console.log('-D2-'); } catch(err){ console.log('CATCHED',err); } console.log('-D8-'); } console.log('-D0-'); test('crash'); console.log('-D9-');
adding the switch() brings up some fancy extras:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); function test( crit){ try{ const arr= new Uint32Array([1,2,3,4]); console.log('-C1-'); switch (crit) { case 'ok': console.log('-C2-C3-'); break; default: console.log('-C2-'); if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz console.log('-C3-'); break; } console.log('-C4-'); } catch(err){ console.log('CATCHED',err); } console.log('-C8-'); } console.log('-C0-'); test('crash'); console.log('-C9-');
expected output (tested on chrome):
-C0- -C1- -C2- CATCHED Error: simulate crash -C8- -C9-
achieved output:
-C0- -C1- -C2- -C4- * should not exist -C8- !!!UNCAUGHTEXCEPTION!!! ... "simulate crash" * should be CATCHED -C9-
-
• #4
I'll look into the exception on Typed Arrays - it shouldn't complain about it at that point - only when you try and write it. I filed an issue for it here: https://github.com/espruino/Espruino/issues/1351
For your
try... catch
I bet you just pasted it into the left-hand side? Espruino bracket-counts to see when it should execute a line, so if you write code with all brackets closed and hit enter then it's executed. If you upload from the right-hand side of the IDE it's got some stuff in there to counteract that.Thanks for the report on the switch as well - I'll have a look at that. There's now an issue filed for it here https://github.com/espruino/Espruino/issues/1352
just a "picture" without words;)
EspruinoWIFI 1v96