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-
@mrQ started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
ok, as promised some sample code to reproduce the second problem when throwing inside a switch statement.
without switch(), everything behaves as expected:
adding the switch() brings up some fancy extras:
expected output (tested on chrome):
achieved output: