异常信息1
来源:互联网 发布:mactalk 人生元编程 编辑:程序博客网 时间:2024/06/02 07:57
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import sssssss.Debug;
/**
* 类 编 号:M00_EccInfoException
* 类 名 称:EccInfoException
* 内容摘要:业务异常类的基类,继承Exception异常类
* 完成日期:
* 作 者:
*/
public class EccInfoException extends Exception
{
/**
* ECC异常值对象类
*/
private EccExceptionInfoBO eccExceptionInfoBO = new EccExceptionInfoBO();
/**
* 方法编号:04
* 方法名称:EccInfoException
* 内容摘要:构造方法,含有异常信息和可抛出类型的入参,调用父类相同的构造方法
*
* @param exceptionMessage
* @param throwable
* @roseuid 431EAAD003AD
*/
public EccInfoException(String exceptionMessage, Throwable throwable)
{
super(exceptionMessage);
}
/**
* 方法编号:03
* 方法名称:EccInfoException
* 内容摘要:构造方法,含有可抛出类型的入参,调用父类相同的构造方法
*
* @param throwable
* @roseuid 431EAA92039F
*/
public EccInfoException(Throwable throwable)
{
super();
}
/**
* 方法编号:02
* 方法名称:EccInfoException
* 内容摘要:构造方法,含有异常信息的入参,调用父类相同的构造方法
*
* @param exceptionMessage
* @roseuid 431EA3E0039C
*/
public EccInfoException(String exceptionMessage)
{
super(exceptionMessage);
}
/**
* 方法编号:01
* 方法名称:EccInfoException
* 内容摘要:空参构造方法,调用父类的空参构造方法
* @roseuid 4316C37E00FD
*/
public EccInfoException()
{
super();
}
/**
* 方法编号:05
* 方法名称:EccInfoException
* 内容摘要:含异常信息的构造期
* @roseuid 4316C37E00FD
*/
public EccInfoException(
String appName,
String errorLayer,
String moduleName,
String className,
String errorCode,
Exception exception)
{
//初始化异常
getEccExceptionInfoBO().getEccExceptionInfoVO().setException(exception);
//设置系统名称
getEccExceptionInfoBO().getEccExceptionInfoVO().setAppName(appName);
//设置异常发生的层
getEccExceptionInfoBO().getEccExceptionInfoVO().setErrorLayer(errorLayer);
//设置模块名称
getEccExceptionInfoBO().getEccExceptionInfoVO().setModuleName(moduleName);
//设置类名称
getEccExceptionInfoBO().getEccExceptionInfoVO().setClassName(className);
//初始化方法名称(调用私有方法自动获得)
getEccExceptionInfoBO().getEccExceptionInfoVO().setMethodName(getMethodName(exception));
//设置异常键
getEccExceptionInfoBO().getEccExceptionInfoVO().setErrorKey(EccExceptionComm.ERROR_KEY);
//设置异常码
getEccExceptionInfoBO().getEccExceptionInfoVO().setErrorCode(errorCode);
//初始化异常消息名称
getEccExceptionInfoBO().getEccExceptionInfoVO().setExceptionMessage(getExceptionDetailsMessage(exception));
}
/**
*方法编号:06
*方法名称:getMethodName
*内容摘要:返回调用该方法的方法名
*
*@param e
*@return methodname
*/
private String getMethodName(Exception e)
{
String input = getExceptionDetailsMessage(e);
StringReader sr = new StringReader(input);
BufferedReader br = new BufferedReader(sr);
String line = "";
String methodName = "";
try
{
//读入一行数据
br.readLine();
line = br.readLine();
}
catch (IOException ex)
{
ex.printStackTrace();
}
//截取"("前的字符串
int paren = line.indexOf('(');
//判断是否存在左括号
if(paren > 0)
{
line = line.substring(0, paren);
//截取"."前的字符串
int period = line.lastIndexOf('.');
//判断是否存在点
if(period > 0)
{
methodName = line.substring(period + 1);
}
else
{
methodName = "SystemMethod";
}
//判断方法名称长度是否大于50字符
if(methodName.length() >50)
{
methodName = "SystemMethod";
}
}
else
{
methodName = "SystemMethod";
}
// 查找iBatis抛出的Exception
if (methodName.equals("SystemMethod"))
{
try
{
// 读取所有异常信息
while (true)
{
// 读取一行
line = br.readLine();
if (line == null)
break;
// 判断是否包含DAO.字样
int nDAO = line.indexOf("DAO.");
if (nDAO > 0)
{
paren = line.indexOf('(', nDAO);
// 是否有括号
if (paren > 0)
{
Debug.println("current line = " + line);
// 取出方法名
methodName = line.substring(nDAO+4, paren);
//判断方法名称长度是否大于50字符
if(methodName.length() >50)
{
methodName = "SystemMethod";
}
break;
}
}
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
//返回处理后的字符串
return methodName;
}
/**
*
* 方法名称: getExceptionDetailsMessage
* 内容摘要: 获得堆栈信息
*
* @param e 异常
* @return String
*/
private String getExceptionDetailsMessage(Exception e)
{
//声明输出信息
String input = null;
//初始化StringWriter
StringWriter sw = new StringWriter();
//初始化PrintWriter
PrintWriter pw = new PrintWriter(sw);
//打印堆栈
e.printStackTrace(pw);
//获得堆栈信息
input = sw.getBuffer().toString();
return input;
}
/**
* @return
*/
public EccExceptionInfoBO getEccExceptionInfoBO()
{
return eccExceptionInfoBO;
}
/**
* @param infoBO
*/
public void setEccExceptionInfoBO(EccExceptionInfoBO infoBO)
{
eccExceptionInfoBO = infoBO;
}
}
- 异常信息1
- huawei--异常:异常编码,异常信息
- js异常分类,异常信息,异常捕获
- oracle异常信息发生
- delphi异常信息捕捉
- 异常处理信息
- 异常信息罗列
- springMVC异常信息
- python 打印异常信息
- java异常信息
- js不报异常信息
- 打印Java异常信息
- 异常信息获取观察
- MyEclpese异常信息
- python 打印异常信息
- 如何分析异常信息
- 异常信息ErrorMessage.properties
- asi异常信息
- HQL: Hibernate查询语言
- 基于Eclipse RCP的油田开发决策支持系统(一)
- “高端”消费
- 看了资料,db2 v9 64位数据库一起动就占很大内存的问题是可以解决,但是不敢改
- Java学习之路:不走弯路,就是捷径
- 异常信息1
- ASP.Net 返回上一页方法集锦
- 基于Eclipse RCP的油田开发决策支持系统(二)
- 左移(右移)运算符结合swich case语句详解
- 100句网络经典语录 (转)
- 基于Eclipse RCP的油田开发决策支持系统(三)
- 微软安全小组公布反制SQL注入的方案-E文
- SQL Server 阻止了对组件 /'Ad Hoc Distributed Queries/' 的访问
- 十六进制 字符串 赋值到 byte