错误捕获
try/catch
你可以使用 try/catch进行错误捕获,适用于未知的错误,即不知道页面会以什么方式进行报错。
class Octopus {
readonly name: string;
readonly numberOfLegs: number = 8;
constructor (theName: string) {
this.name = theName;
}
}
let dad = new Octopus("Man with the 8 strong legs");
dad.name = "Man with the 3-piece suit"; // 错误! name 是只读的.
状态码判断
example:
if (res.code === 200) {...}
else {...}
适用于可以预知的错误,即知道如果此接口出错,应该做出什么操作。