سؤال

I have the following code in a velocity template theme:

#set($currLayout = $layoutLocalService.getFriendlyURLLayout($group_id, true, $currFriendlyUrl))

which throws a

com.liferay.portal.NoSuchLayoutException
    at com.liferay.portal.service.impl.LayoutLocalServiceImpl.getFriendlyURLLayout(LayoutLocalServiceImpl.java:959)

when matching layout not exist.

How could I catch this exception in my velocity template?

هل كانت مفيدة؟

المحلول

To my knowledge, it is not possible to catch exceptions inside a velocity template. Generally, there are two ways of dealing with such a situation:

  • handle the exception in the application which uses the template, such as a servlet
  • avoid throwing exceptions; instead, have the method always return a valid (default) value, or null if that is not possible

The velocity manual recommends to use the second option whenever possible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top