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 艾龙,
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;
}