Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to handle exceptions / errors in LiveCycle

Avatar

Level 9

Hello All ,

I want to handle some exception / errors that may arise while the user is filling the form so that the JavaScript console should not show any error rather we can simply show an alert / message .

Say I got a dynamic table where the user can add / delete row at run time . There is a minimum count for the no.of rows . Suppose the user clicks the delete button without adding a new row then the JavaScript console will show error . I know we can handle this by using if else statements where depending on the instance manager count the deletion of rows are permitted . I want to know is it possible here to write a code to handle exception considering this thing as an exception without using the If-else statement ?? Just a thought.

Thanks.

Bibhu.

1 Reply

Avatar

Former Community Member

What you're looking for is the javascript:

try{

// code

} catch (err) {

// fail code

}

However, this is not the right way to solve your problem: Exception handling is for handling exceptions, and a scenario that you know can come to pass (such as the user clicking the removeInstance button when there are none to remove) is not an exception.

Don't misunderstand me - putting code inside try/catch is 'good developer manners' (I do it myself all the time), and I strongly encourage you to do the same. Although only for handling exception sprung from code that you think should work just as fine without them.

A better way of solving your particular problem is to remove the minus-button if there are no instances to remove.