如果我们抛出了 ServletException,如何在日志中写入任何内容?
如果我的 servlet 抛出 ServletException,我想在日志中添加一个条目
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException{
try {
} catch (ServletException e) {
log.warn("error");
throw new SerletException(e);
}
它会递归吗?这是处理异常的正确方法吗?
I want to make an entry in the log if my servlet throws ServletException
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException{
try {
} catch (ServletException e) {
log.warn("error");
throw new SerletException(e);
}
Will it recurse? Is it the right way to handle exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不会有递归,但是没有必要将异常包装在另一个递归中。只需简单地抛出
e
即可。顺便说一句,更好的地方是
Filter
,它映射到/*
URL 模式,这样您就不需要在所有 servlet 中重复它。No, there will be no recursion, but wrapping the exception in another one is unnecessary. Just throw
e
plain.By the way, a better place for this is a
Filter
which is mapped on an URL pattern of/*
, so that you don't need to repeat it in all servlets.