try { // 这里故意写错函数名,为了抛出错误 console.logg('This is an error and will not display'); } catch (e) { console.log(e); // TypeError: console.logg is not a function console.log(e.message); // console.logg is not a function console.log(e.name); // TypeError console.log(e.stack); // TypeError: console.logg is not a function }
try { console.log('This will display.'); throw('My error position.'); // throw 将会中断语句的执行 // 同样故意制造错误 console.logg('This is an error and will not display.'); // 后面是正常语句 console.log('This will not display, either.') } catch (e) { console.log(e); } // This will display. // My error position.
try { console.logg('This is an error and wil not display.'); throw('My error position.'); // 后面的执行同样会被中断 console.log('This will not display, either.') } catch(e) { console.log(e); } // TypeError: console.logg is not a function.