function demo() {
return 1;
console.log('我是SeriousLose');
return 2;
}
console.log(demo()); // 1
function demo() {
try {
return 1;
} catch (err) {
console.log(err);
return 2;
} finally {
return 3;
}
}
console.log(demo()); // 3
function demo() {
try {
return 1;
} catch (err) {
console.log(err);
return 2;
} finally {
try {
return 3;
} finally {
return 4;
}
}
}
console.log(demo()); // 返回 4
// 获取调用栈信息
function firstFunction() {
secondFunction();
}
function secondFunction() {
thridFunction();
}
function thridFunction() {
console.log(new Error().stack);
}
firstFunction();
//=> Error
// at thridFunction (<anonymous>:2:17)
// at secondFunction (<anonymous>:5:5)
// at firstFunction (<anonymous>:8:5)
// at <anonymous>:10:1
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.https://serious-lose.notion.site/JS-Error-27bc95352b1b47f2b271a0b3fb36212b