我在速度模板主题中有以下代码:
#set($currLayout = $layoutLocalService.getFriendlyURLLayout($group_id, true, $currFriendlyUrl))
抛出一个
com.liferay.portal.NoSuchLayoutException
at com.liferay.portal.service.impl.LayoutLocalServiceImpl.getFriendlyURLLayout(LayoutLocalServiceImpl.java:959)
当匹配的布局不存在时。
如何在我的速度模板中捕获此异常?
最佳答案
据我所知,不可能捕获速度模板内的异常。一般来说,处理这种情况有两种方法:
- 处理使用模板的应用程序中的异常,例如servlet
- 避免抛出异常;相反,让该方法始终返回有效(默认)值,如果不可能,则返回
null
velocity manual建议尽可能使用第二个选项。
关于exception - 当未找到布局时,如何捕获 Liferay Velocity 主题中的 NoSuchLayoutException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16088170/