我正在从我的对象的方法throw中获取异常。但是我无法使用块来解决该错误。onloadXMLHttpRequestcatchtry catch
我的函数中有以下代码_fetch(url, callback):
const xhr = new XMLHttpRequest()\n\nxhr.onload = function () {\n if (xhr.readyState === xhr.DONE) {\n // if (xhr.status === 200) callback(xhr.response)\n\n // throw a \'custom\' error if the server responds with 501\n if (xhr.status === 501) throw new Error(\'Answer not found\') /\n }\n}\n\n// rest of the fn\nRun Code Online (Sandbox Code Playgroud)\n\n然后,我正在使用该_fetch功能:
try {\n _fetch(endPoint, response => console.log(response))\n} catch (error) { // error not caught\n console.log(error)\n}\nRun Code Online (Sandbox Code Playgroud)\n\n …