【发布时间】:2009-08-13 20:10:43
【问题描述】:
我目前正在使用一个非常简单的 MVC 框架,Bear Bibeault's Front Man,对于那些不熟悉的人来说,它与 Spring MVC 非常相似(至少在概念上)。我遇到的问题之一是如何正确处理异常。
我目前正在做这样的事情,
try {
//do something
}catch (Exception ex) {
logger.error("Logging error", ex);
Map model = new HashMap();
model.put("error", ex.getLocalizedMessage());
cc.setScopedVariable("model", model);
cc.forwardToView(ERROR_VIEW);
}
基本上我会记录异常,然后转发到错误视图页面。
然而,这让我觉得这不是正确的做法。这会导致很多样板代码不是很干。
在 Web 应用程序中处理/记录异常的更好方法是什么?
【问题讨论】:
标签: java model-view-controller exception web-applications error-handling