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’
- 全局严格模式
- 局部函数内严格模式
本文介绍了JavaScript中使用try...catch进行异常处理的方法,包括不同类型的错误及其触发条件。此外,还探讨了ES5中的严格模式如何帮助开发者编写更高质量的代码。
474

被折叠的 条评论
为什么被折叠?



