Atitit.js javascript异常处理机制与java异常的转换.js exception process Voae
1. 1. javascript异常处理机制
Throw str
Not throw error ..cause ie,ff error obj is diff..
2. 2. Web前后台异常的统一处理
不个java异常转换成个js异常走ok...
dwr中看见了dwr的异常转换,三,不生效...仅仅好输出str来转换...
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax
3. java异常转换为js异常
elmtC.fileChangeEvent($("#filePath").val(),function(data)
{
processJavaEX(data);
var plt_s=secs2str(data.Duration);
$('#playtime').timespinner('setValue',plt_s);
});
3. -------------具体代码
if (NoSetAwd(activityId)) {
RuntimeException e=new RuntimeException("e:noSetAwdErr此活动还没设置奖品哟.");
String s= JSONObject.toJSONString(e);
return s;
}
//{"@type":"java.lang.RuntimeException","localizedMessage":"e:noSetAwdErr 此活动还没设置奖品哟.","message":"e:noSetAwdErr此活动还没设置奖品哟.","stackTrace": [{"className":"com.focustar.servlet.AwardServlet","fileName":"AwardServlet.java","lineNumber":132,"methodName":"main","nativeMethod":false}],"suppressed":[]}
function logx(msg) {
try {
console.info("----------from logx");
console.info("--"+msg);
} catch (e) {
// not support console method (ex: IE)
}
}
function processJavaEX(data)
{
if(typeof data=="string")
data = eval( "(" + data + ")" );
if(data["@type"]!=null && data["@type"]=="java.lang.RuntimeException")
{
if(data.message!=null)
logx(data.message);
throw data.message;
}
if(data["stackTrace"]!=null)
{
if(data.message!=null)
logx(data.message);
throw data.message;
}
else
return false;
}
參考
Atititjs javascript异常处理机制与java异常的转换.js exception process - attilax的专栏 - 博客频道 - CSDN.NET.htm