我希望当函数sum的两个参数是数字时,代码成功,但是当两个参数中的一个不是数字时,我想抛出一个异常。const sum = (num1: number, num2: number) => { };
typeof sum(8,'A') === 'number'; console.log('the type you entered is
我使用的是Angular和TypeScript。在API调用的情况下,我使用了trycatch结构来处理错误。如果try块中出现任何错误,那么它根本不会去catch块。应用程序仅在那里终止。以下是示例代码片段,
this.api.getAPI(Id).subscribe( // this.api is my api service and getAPI is presentEmpty response'