栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

返回JavaScript代码时如何在PHP / Dojo中正确生成异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

返回JavaScript代码时如何在PHP / Dojo中正确生成异常

这是一个片段,可从xhr-get请求中检测与网络无关的错误,并在控制台中输出有关此错误的一些信息。

还有一个额外的isevalError()函数可以处理所有eval-
error类型……我并不为此感到骄傲。更好的方法是获取errorMessage子类的父对象。我认为您通常可以放弃isevalError(),因为在此块中不应有任何其他错误。

function isevalError(errorMessage){    return errorMessage.name == "RangeError" ||    errorMessage.name == "ReferenceError" ||    errorMessage.name == "SyntaxError" ||    errorMessage.name == "URIError" ||    errorMessage.name == "TypeError";}var foo = dojo.xhrGet({    url: 'stacko.js',    handleAs: "javascript",    load: function(returnValue) {        console.log("load: "+returnValue);    },    error: function(errorMessage,ioargs) {        //request worked fine, this must be a non-network related error        if(ioargs.xhr.readyState == 4 && ioargs.xhr.status == 200) { if(isevalError(errorMessage)){     //show eval-error, url request & the JS pre that causes the exception     //eval-error types: RangeError,ReferenceError,SyntaxError, URIError, TypeError     console.error(errorMessage.name+" in JS Code detected: (url: "+ioargs.url+")")     console.error("Error Message: "+ errorMessage);     console.error(ioargs.xhr.responseText); } //a little reflection - if u want to know who triggered this error  //(although in this case the output is not very helpful ) console.error("Error triggered by: "+arguments.callee.caller.toString()); //last but not least log the error & the xhr-request object for more information console.error("XHR Object:"); console.error(ioargs); console.error("Error Object:"); console.error(errorMessage);        }    }});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/427423.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号