Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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.