Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Best way to catch component exception / error

Avatar

Level 4

Hi,

I am creating a JSON output for markup exposed by my custom component. In this JSON i have 2 attributes (componentMarkup , successFlag). If there is no issue in component execution then i set the "successFlag" to TRUE else FALSE.

What is the best way to know that some exception occurred during component execution ? This will help me in setting this "successFlag" for my JSON. I want to wrap entire component JSP code around some try / catch so that if there is any exception anywhere in JSP it will set successFlag to FALSE


One way to do this using <c:catch> . Are there any other better way to do this ?
 

<c:catch var ="catchException"><% int x = 5/0;%></c:catch><c:if test = "${catchException != null}"><p>The exception is : ${catchException} <br />There is an exception: ${catchException.message}</p></c:if>
1 Accepted Solution

Avatar

Correct answer by
Level 10

Using JSP tags - like you mention is a good way.  We are releasing a community article next week on this use case.  This URL to this article will be posted in this community. 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Using JSP tags - like you mention is a good way.  We are releasing a community article next week on this use case.  This URL to this article will be posted in this community.