try 可以将容易出错的代码(对缓存的操作,http请求,文件的上传,下载)使用这个语句
允许测试代码块中的错误。
catch 捕捉错误
<script>try{alertt("http")}catch(err){console.log(err)}console.log("hello world")/*ReferenceError: alertt is not definedat 01try-catch.html:11hello world*/</script>
throw 可以自定义一个错误
<script>
var arr = "";
try{
if(Array.isArray(arr)){
console.log(err)
}else{
throw "必须传入一个数组"
}
}catch(err){
console.log(err)
}
</script>
