Best Practices

When writing code for handling errors, remember these best practices:

  • The business service foundation provides methods that you can use to add prefix messages to errors. You should add useful information such as key information or detail line information when returning error messages. If you add a prefix to an E1MessageList object that contains no errors, no prefix will be appended and no error will be thrown.

    This example shows how to add a prefix, which names the business function where the messages occurred, to the message list:

    bsfnParams.getE1MessageList().setMessagePrefix("AddressBookMasterMBF
    (N0100041): ");
    

    If the prefixed text can be translated to another language, use a business service property with this naming convention for the text:

    BSSVname_PREFIX_sequence

    Use this code to attach the business service property as a prefix in an error message:

    private static final String SVC_PROPERTY_PHONE_ERR_PREFIX = 
    "JR010030_PREFIX_1";
    ...
    phonesMessages.setMessagePrefix(SVC_PROPERTY_PHONE_ERR_PREFIX +(i+1));
    
  • If an error condition that is not handled by the business function call occurs, you can use a business service foundation method to create a new error and add the error to the message list. This can be used when a checked exception is thrown by business service foundation and you want to collect the exception as a message in the E1MessageList. Examples of situations requiring a new E1Message are calling the BSSVDataFormatter utility and retrieving business service properties. Because the alias for the JD Edwards EnterpriseOne error to be returned must be passed to the method, an error data dictionary item must exist in JD Edwards EnterpriseOne.

    This code shows creating a new E1Message:

    new E1Message(context, "001FIS", PROGRAM_ID);