例外のハンドリング
try {
throw new Error('Something bad happened');
}
catch(e) {
console.log(e);
}エラーサブタイプ
RangeError
// Call console with too many arguments
console.log.apply(console, new Array(1000000000)); // RangeError: Invalid array lengthReferenceError
'use strict';
console.log(notValidVar); // ReferenceError: notValidVar is not definedSyntaxError
TypeError
URIError
常にエラーを使用する
あなたはエラーをスローする必要はありません
例外的なケース
どこに投げられるのか不明
優雅なハンドリングを困難にする
型システムでうまく表現されていない
最終更新