异步函数抛出的异常没有被 catch 块捕获

时间:2021-03-28 18:29:44

标签: javascript typescript asynchronous async-await

我的 Typescript 代码如下所示:

    myFunction = async (param: string) : Promise<string, null> => {
        //some synchronous code here
        try {
            await anotherAsyncFnWhichisThrowingAnException();
        }
        catch(err) {
            //this code is not reached even on an exception
        }
    }

即使当 anotherAsyncFnWhichisThrowingAnException 抛出异常时,catch 块中的代码也不会被执行。为什么会这样,我怎样才能捕捉到这个异常?

0 个答案:

没有答案