• just a "picture" without words;)

    1. process.on('uncaughtException', function(err) {
    2. console.log('!!!UNCAUGHTEXCEPTION!!!',err);
    3. });
    4. const arr= new Uint32Array([1,2,3,4]); // or any other ArrayView
    5. console.log('test E...');
    6. if (!E.xyz) console.log('E ok'); // works as expected
    7. console.log('test arr...');
    8. if (!arr.xyz) console.log('arr ok'); // throws exception - not as expected
    9. console.log('done all ok');

    EspruinoWIFI 1v96

  • Some more suspicious things...

    This behaves as expected:

    1. process.on('uncaughtException',(err)=>{
    2. console.log('!!!UNCAUGHTEXCEPTION!!!',err);
    3. });
    4. const arr= new Uint32Array([1,2,3,4]);
    5. console.log('-A1-');
    6. if (!!arr.xyz) console.log('-A2-');
    7. console.log('-A3-');

    But this

    1. process.on('uncaughtException',(err)=>{
    2. console.log('!!!UNCAUGHTEXCEPTION!!!',err);
    3. });
    4. const arr= new Uint32Array([1,2,3,4]);
    5. console.log('-B1-');
    6. try{
    7. if (!!arr.xyz) console.log('-B2-');
    8. console.log('-B3-');
    9. }
    10. catch(e){
    11. console.log('-B4-',e);
    12. }
    13. console.log('-B5-');

    reports some strange error (see 2nd UNCAUGHTEXCEPTION message):

    1. -B1-
    2. !!!UNCAUGHTEXCEPTION!!! Error {
    3. "msg": "Field or method \"xyz\" does not already exist, and can't create it on Uint32Array",
    4. "type": "Error",
    5. "stack": " at line 2 col 12\n if (!!arr.xyz) console.log('-B2-');\n ^\n"
    6. }
    7. !!!UNCAUGHTEXCEPTION!!! SyntaxError {
    8. "msg": "Got catch expected EOF",
    9. "type": "SyntaxError",
    10. "stack": " at line 1 col 1\ncatch(e){\n^\n"
    11. }
    12. -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...

  • ok, as promised some sample code to reproduce the second problem when throwing inside a switch statement.

    without switch(), everything behaves as expected:

    1. process.on('uncaughtException',(err)=>{
    2. console.log('!!!UNCAUGHTEXCEPTION!!!',err);
    3. });
    4. /*
    5. expect output === achieved output:
    6. -D0-
    7. -D1-
    8. CATCHED ... "simulate crash"
    9. -D8-
    10. -D9-
    11. */
    12. function test( crit){
    13. try{
    14. const arr= new Uint32Array([1,2,3,4]);
    15. console.log('-D1-');
    16. if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz
    17. console.log('-D2-');
    18. }
    19. catch(err){
    20. console.log('CATCHED',err);
    21. }
    22. console.log('-D8-');
    23. }
    24. console.log('-D0-');
    25. test('crash');
    26. console.log('-D9-');

    adding the switch() brings up some fancy extras:

    1. process.on('uncaughtException',(err)=>{
    2. console.log('!!!UNCAUGHTEXCEPTION!!!',err);
    3. });
    4. function test( crit){
    5. try{
    6. const arr= new Uint32Array([1,2,3,4]);
    7. console.log('-C1-');
    8. switch (crit) {
    9. case 'ok':
    10. console.log('-C2-C3-');
    11. break;
    12. default:
    13. console.log('-C2-');
    14. if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz
    15. console.log('-C3-');
    16. break;
    17. }
    18. console.log('-C4-');
    19. }
    20. catch(err){
    21. console.log('CATCHED',err);
    22. }
    23. console.log('-C8-');
    24. }
    25. console.log('-C0-');
    26. test('crash');
    27. console.log('-C9-');

    expected output (tested on chrome):

    1. -C0-
    2. -C1-
    3. -C2-
    4. CATCHED Error: simulate crash
    5. -C8-
    6. -C9-

    achieved output:

    1. -C0-
    2. -C1-
    3. -C2-
    4. -C4- * should not exist
    5. -C8-
    6. !!!UNCAUGHTEXCEPTION!!! ... "simulate crash" * should be CATCHED
    7. -C9-
  • 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

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
    • $ Donate
About

Exception when testing non-existent property of Uint32Array and bug with throw inside switch()

Posted by Avatar for mrQ @mrQ

Actions