📜  javascript 获取错误行号 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:05.139000             🧑  作者: Mango

代码示例1
function getErrorObject(){
    try { throw Error('') } catch(err) { return err; }
}

var err = getErrorObject();
var caller_line = err.stack.split("\n")[4];
var index = caller_line.indexOf("at ");
var clean = caller_line.slice(index+2, caller_line.length);