tips.1 try…catch
- try…catch语句将能引发错误的代码放在try块中,并且对应一个响应,然后有异常被抛出。
try {
} catch (e) {
console.log(e.name, e.message);
} finally {
console.log('over');
}
常见错误类型
- EvalError : raised when an error occurs executing code in eval()
- RangeError : raised when a numeric variable or parameter is outside of its valid range
- ReferenceError : raised when de-referencing an invalid reference
- SyntaxError : raised when a syntax error occurs while parsing code in eval()
- TypeError : raised when a variable or parameter is not a valid type
- URIError : raised when encodeURI() or decodeURI() are passed invalid parameters
tips2.ES5严格模式
- ‘use strict’
- 全局严格模式
- 局部函数内严格模式