Hi,
I want to be able to catch all exceptions that occur at the component level, and display a friendly error message within that component without affecting the rest of the page rendering. What is the best way to do this?
Thanks in advance for your help.
Jason
Solved! Go to Solution.
Views
Replies
Total Likes
CQ components are just JSP scripts. So you can display an error message in a DIV. Hide the DIV when you do not want to display the message.
Views
Replies
Total Likes
<c:catch var ="catchException">
<c:set var="test" value="object.title" />
</c:catch>
<c:if test = "${catchException != null}">
<%@include file="/apps/sni-core/error.jsp" %>
</c:if>
In the error jsp we will display a message saying:
<%
Logger logger=Logger.getLogger(this.getClass().getName());
String errorMessage = pageContext.findAttribute("catchException");
logger.error("Exception Occurred in the module : " + errorMessage);
%>
There is an exception while rendering this module. then the exception occurred is : ${catchException}
we can even print the exception to a log file.
we just need to add "<c:catch var ="catchException">" in every module, so that we can handle the errors at module levels.
Views
Replies
Total Likes
CQ components are just JSP scripts. So you can display an error message in a DIV. Hide the DIV when you do not want to display the message.
Views
Replies
Total Likes
As Scott pointed out, it's possible to handle the errors straight away when they arise on the JSP page.
There are a few examples here of how you could do it: http://www.tutorialspoint.com/jsp/jsp_exception_handling.htm
If would maybe make use of the try/catch blocks so you can handle the errors nicely on the actual component jsp and you could do create some nice
html for the catch block so that the component would look good anyway. That might include a special DIV when an error arise but it would not display that part if everything went fine.
/Johan
Views
Replies
Total Likes
Ojjis wrote...
As Scott pointed out, it's possible to handle the errors straight away when they arise on the JSP page.
There are a few examples here of how you could do it: http://www.tutorialspoint.com/jsp/jsp_exception_handling.htm
If would maybe make use of the try/catch blocks so you can handle the errors nicely on the actual component jsp and you could do create some nice
html for the catch block so that the component would look good anyway. That might include a special DIV when an error arise but it would not display that part if everything went fine.
/Johan
Thank you for your replies, I appreciate it. I was trying to get away from enforcing a rule that all developers be required to add a general try/catch block around all of the code for their individual components. What I was looking for was some way to automatically add a try/catch block around any component dropped onto a page, but to have the code that does that in only one place. Is there a way to do this?
Thanks!
Jason
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies