目前我的异常(exception)是记录文本和堆栈跟踪:
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 。我必须查看每个方法并检查它是否使用参数。这将花费我几天的时间。代码中有成千上万的异常,是否有一种简单的方法来显示这些值?
最佳答案
您可以使用 slf4j-ext 来记录方法参数。它们记录在跟踪级别。
private static final XLogger xlogger = XLoggerFactory.getXLogger(MyClass.class);
然后您可以像这样在方法的开始和结束处使用:
protected void Method1(Message aMessage){
xLogger.entry(aMessage);
...
xLogger.exit();
}
关于java - 在 Java 中从方法中抛出异常记录参数值的简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917057/