Atitit.部分错误 设计模式,异常处理框架atiPartErr 的总结
1. 流程图
要是部分错误,alert 一个
未能全部完成处理:
r=r+"\r\n"+"数据id:"+eItem.id +" 提示:"+eItem.msg;
r=r+"\r\n"+"数据id:"+eItem.id +" 提示:"+eItem.msg;
2. Java 类关系结构图片
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:[email protected]
转载请注明来源: http://blog.csdn.net/attilax
3. 错误信息结构
"[ {\r\n \"id\" : \"5\",\r\n \"msg\" : \"HasReltDataEx\"\r\n}, {\r\n \"id\" : \"8\",\r\n \"msg\" : \"unkk\"\r\n} ]",
4. 调用
private String multiDel_byDwr()
{
try {
returnmultiDel();
} catch (PartProcessErrEx e) {
e.setTypex("PartProcessErrEx");
return toJsonStr( e);
}
//return toJsonStr(new PartProcessErrEx(pex.li, "PartProcessErrEx"));
}
private String multiDel() throws PartProcessErrEx {
PartErrX pex = new PartErrX();
for (int i = 0; i < 10; i++) {
try {
del(i);
} catch (HasReltDataEx e) {
ErrorItem ei = new ErrorItem();
ei.id = String.valueOf(i);
ei.msg = "HasReltDataEx";
pex.add(ei);
e.printStackTrace();
} catch (Exception e) {
ErrorItem ei = new ErrorItem();
ei.id = String.valueOf(i);
ei.msg = e.getMessage();
pex.add(ei);
e.printStackTrace();
}
}
if (pex.li.size() == 0)
return "ok";
throw (new PartProcessErrEx( JsonUtil4jackjson.buildNormalBinder().toJson(pex.li) ));
}
4.1. 收集错误信息
} catch (HasReltDataEx e) {
ErrorItem ei = new ErrorItem();
ei.id = String.valueOf(i);
ei.msg = "HasReltDataEx";
pex.add(ei);
4.2. 判断是否部分错误抛出异常
if (pex.li.size() == 0)
return "ok";
throw (new PartProcessErrEx( JsonUtil4jackjson.buildNormalBinder().toJson(pex.li) ));
4.3. 设置typex信息4 js
private String multiDel_byDwr()
{
try {
returnmultiDel();
} catch (PartProcessErrEx e) {
e.setTypex("PartProcessErrEx");
return toJsonStr( e);
}
//ret
5. Js解析 ,throw js 异常
try{
processJavaEX(data);
//some();
logx("someth");
}catch(e)
{
//catch check ex
if(e instanceof JavaEx )
{
//catch PartProcessErrEx ex
if(e.typex=="PartProcessErrEx")
{
//alert(e.message);
alert(formatPartE(e.message,"未能全部完成处理:"));
throw "stop..";
}
}
6. Js 格式化
// JavaScript Document
function formatPartE(s,title)
{
var r=title;
var data = eval( "(" + s + ")" );
// for (var eItem in data)
for(var i=0; i<data.length; i++)
{
var eItem=data[i];
r=r+"\r\n"+"数据id:"+eItem.id +" 提示:"+eItem.msg;
}
return r;
}