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

handling exception in custom components

neptas
Level 6
Level 6
Hello,



Is there any info about handling exceptions in custom components? I would like to expose some exceptions to the Livecycle process.



Thank you
2 Replies
Jasmin_Charbonn
Level 10
Level 10
Unfortunately there is not a lot of documentation on that area.



This is a quick example I built a while ago. The list of exceptions the function can throw which are JasException (which is a custom exception), and FileNotFoundException are what you're going to see in the list from the lightning bolt.



Jasmin



public void ReadFile(String code) throws JasException,FileNotFoundException{



System.out.println("!!!******** Init Compontent with value " + code);

code = "3";



if(code.equalsIgnoreCase("1")){

System.out.println("***** In code 1");

throw new JasException();

}



try{

if(code.equalsIgnoreCase("2")){

System.out.println("***** In code 2");

FileInputStream fstream = new FileInputStream("textfile.txt");

}

}

catch (Exception e){

throw new FileNotFoundException();

}



if(code.equalsIgnoreCase("3")){

int intCode = 0;

intCode = intCode /0;

}



System.out.println("******** End Compontent");

}
Sentah
Level 2
Level 2
I have faced this situation for a while and found solution.



1.Create your custom Exception say (custom exception)

2. Set the properties like errorcode,errormessage, and throwable (if u want to bubble up the exceptions).

3. Create a custom object to hold the results (i.e like a java bean)

4. In your custom component methods just return the custom object and set exception as a property.



for e.g.



public class CustomReturn {



private String result;

private CustomException exception;



//getters & setters

}



public class CustomException {



private int errorCode = -1;

private String errorMessage;

private Throwable error;



//getters & setters

}



public class CustomClass {



public CustomReturn testValue() {

CustomReturn returnValue = new CustomReturn();



try {

//perform operations

}

catch(Exception ex) {

CustomException cex = new CustomException ();

cex .setErrorCode(1000);

cex .setErrorMessage(ex.getMessage());

cex .setErr(ex);

returnValue .setException(cex);

}



return returnValue;

}

}



return returnValue;



As you see , you can check for the exception in your return type using the bean property.



This will overcome the limitation of not able to retrieve the error stack incase of errors with default livecycle components.



Hope this helps.



-Senthil