💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 异常信息捕获 ``` try{ console.log(num); }catch(e){ //->形参必须要写,我们一般其名为e console.log("有错误~") console.log(e.message) } console.log("ok"); ``` try catch完整版 ``` try{ //<js code> }catch(e){ //如果代码报错执行catch中的代码 }finally{ //一般不用:不管try中的代码是否报错,都要执行finally中的 } ``` 有时候既想捕获到错误的信息,又不想让下面的代码继续执行 ``` try{ console.log(num); }catch(e){ //->手动抛出一条错误信息,终止往下执行代码 throw new Error("当前网络繁忙,请稍后再试"); } console.log("ok"); ``` 其它快捷错误创建 ``` new ReferenceError ->引用错误 xxx is not defined new TypeError ->类型错误 xxx is not a function new RangeError ->范围错误 ```