记录Java中方法引发的异常中的参数值的简单方法

记录Java中方法引发的异常中的参数值的简单方法,java,exception,exception-handling,Java,Exception,Exception Handling,目前我的例外情况是记录文本和堆栈跟踪: throw new RequestValidationException("test exception", parameters, e); 我想收集所有方法中抛出异常的所有参数 HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("testparam", message.toString());

目前我的例外情况是记录文本和堆栈跟踪:

throw new RequestValidationException("test exception", parameters, e);
我想收集所有方法中抛出异常的所有参数

HashMap<String, String> parameters = new HashMap<String, String>();   
        parameters.put("testparam", message.toString());

throw new RequestValidationException("test exception", parameters, e);
HashMap参数=新的HashMap();
parameters.put(“testparam”,message.toString());
抛出新的RequestValidationException(“测试异常”,参数e);

现在我使用的是hashmap。我必须检查每个方法,并检查它是否使用参数。这将花费我几天的时间。代码中有数千个异常,是否有一种简单的方法显示值?

您可以使用slf4j ext记录方法参数。它们是在跟踪级别记录的

private static final XLogger xlogger = XLoggerFactory.getXLogger(MyClass.class);
然后,您可以在开始和结束时使用以下方法:

protected void Method1(Message aMessage){
    xLogger.entry(aMessage);
    ...
    xLogger.exit();
}

你的意思是自动的,还是你在寻求一种方法来创建包含参数值的消息?我不太清楚你想要实现什么。你能提供一些伪代码来说明你正在寻找的行为吗?