Getting error line number from catch block

try{
    cause error  
}
catch(err){  
    console.log(err.lineNumber) //or console.log(err.line)
}

The error object supports multiple things such as err.name, err.stack, and err.message but I can’t find anything that works for logging the line of the error and filename. For example the stack actually shows the information I want that being "loader.js:13:22" but it’s also the full stack. I’m sorry if this isn’t a question I should be asking here but I’ve tried many "solutions" that haven’t worked. Thank you in advance.

EDIT: Used this package https://www.npmjs.com/package/stack-trace supports everything I could ever need, thanks all.

69 thoughts on “Getting error line number from catch block”

Leave a Comment