当 DataGrid 正在呈现时,如果它在途中遇到错误(在我的情况下,通常使用 cell.formatter 或 cell.get),网格会捕获异常,中止整个过程,并简单地发出模糊的消息,“对不起,发生错误”。
有没有办法抑制异常捕获,以便在发生错误时出现在调试控制台中?
当 DataGrid 正在呈现时,如果它在途中遇到错误(在我的情况下,通常使用 cell.formatter 或 cell.get),网格会捕获异常,中止整个过程,并简单地发出模糊的消息,“对不起,发生错误”。
有没有办法抑制异常捕获,以便在发生错误时出现在调试控制台中?
我没有找到使用 dojo 的默认行为的方法,因此作为一种解决方法,我制作了一个小实用程序来更改布局结构,然后再将其传递给网格。(有点骇人听闻,但我在脚本中制作了网格,而不是使用标记,所以它现在可以工作,而且一个新的网格无论如何都在绘图板上......
lib.wrapTryCatch = function(call, onException){
onException = onException || function(e){
console.log({wrappedException: e});
return e.message;
};
var f = function tryWrapper(){
try{
var val = call.apply(this, arguments);
return val;
}
catch(e){
return onException(e);
}
}
f.wrapped = call;
f.onException = onException;
return f;
}
lib.gridUtils = {
/** Convenience/debugging function to make exceptions visible
* if grid structure cells have errors.
*
* Puts exception to the console, instead of the grid's default
* behavior of dying silently
*
* */
decorateStructure: function(structure){
for(var idx in structure){
cell = structure[idx];
if('get' in cell){
cell.get = lib.wrapTryCatch(cell.get);
}
if('formatter' in cell){
cell.formatter = lib.wrapTryCatch(cell.formatter);
}
}
return structure;
}
}