たとえば、Windows Script Host を使用して .JS ファイルとして実行する次のコードがあるとします。
try
{
ProduceAnError();
}
catch(e)
{
//How to get an error line here?
}
エラー(例外)が発生したエラー行を知る方法はありますか?
私の別の回答で申し訳ありません。あまり役に立ちませんでした:P
あなたが探しているのは、ReferenceError のスタック プロパティだと思います。catch に渡す引数を使用してアクセスできます。
try {
someUndefinedFunction("test");
} catch(e) {
console.log(e.stack)
}
出力例:
ReferenceError: someUndefinedFunction is not defined
at message (http://example.com/example.html:4:3)
at <error: TypeError: Accessing selectionEnd on an input element that cannot have a selection.>
at HTMLInputElement.onclick (http://example.com/example.html:25:4)