有沒有辦法解決throwjavascript錯誤并強制縮進?而不是'Error'成為' Error'。如果沒有,我可以用什么代替,那肯定會退出我的 node.js 行程。謝謝。
uj5u.com熱心網友回復:
您無法修改節點顯示未捕獲錯誤的方式。但是,在退出程式之前,您可以捕獲錯誤并選擇以您想要的方式顯示它。
class SpecialError extends Error {}
function main() {
// ...
throw new SpecialError('Whoops!')
}
// This is at the very end, so when the catch finishes,
// there's nothing left to execute, and the program ends.
try {
main()
} catch (err) {
if (!(err instanceof SpecialError)) throw err
console.error([
` Error: ${err.message}`, // Lots of indentation
...err.stack.split('\n').slice(1)
].join('\n'))
// Makes the program exit with status code 1. See here: https://nodejs.org/api/process.html#process_process_exitcode
// Uncomment this when you're in node.
// process.exitCode = 1;
}
uj5u.com熱心網友回復:
我不知道我是否真的理解你的問題,但你有沒有嘗試過這樣的事情?
throw new Error('\tSome error message.');
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324124.html
標籤:javascript 例外 扔
上一篇:處理來自dao的預期例外
