Class ErrorCode

java.lang.Object
com.saperion.common.lang.exception.ErrorCode
All Implemented Interfaces:
Serializable

public abstract class ErrorCode extends Object implements Serializable

Base class of all error codes for BaseExceptions.

The error code consists of an obligatory "product" an optional "module" and an obligatory "number". Product and module should be short or abbreviations and should follow a pattern standardized by conventions.

In its written form (see getString()) the parts will be converted to upper case, combined and separated by an "-"-character, f.e. "JCR-4711" or "ECM-TPS-42".

toString() creates a string for debugging and protocol purpose and should not be used for business semantics.

It is recommended for all products to create their own product-specific extension of ErrorCode encapsulating the product-name-part of the error code, f.e.:

 public class MyProductErrorCode extends ErrorCode
 {
     private static final String PRODUCT = "JCS";
 
     public MyProductErrorCode(String module, int number)
     {
         super(PRODUCT, module, number);
     }
 
     public MyProductErrorCode(int number)
     {
         super(PRODUCT, number);
     }
 }
 
A product can also enforce the use (or no use) of the module part by omitting one of the constructors in its own error code extension.

Author:
agz
See Also:
  • Field Details

    • SERARATOR

      protected static final String SERARATOR
      The separator to use when formatting the written form.
      See Also:
  • Constructor Details

    • ErrorCode

      public ErrorCode(String product, String module, int number)
      Creates a new ErrorCode with the specified product, module and number.

      The specified product must not be null or empty.

      The specified module is optional (may be null).

      The specified number must be greater than 0.

      Parameters:
      product - product of the new error code
      module - module of the new error code
      number - number of the new error code
    • ErrorCode

      public ErrorCode(String product, int number)
      Creates a new ErrorCode with the specified product, module and number.

      The specified product must not be null or empty.

      The specified number must be greater than 0.

      Parameters:
      product - product of the new error code
      number - number of the new error code
  • Method Details

    • getProduct

      public final String getProduct()
      Returns the product (upper case).
      Returns:
      the product
    • getModule

      public final String getModule()
      Returns the module (upper case) or null if no module was specified.
      Returns:
      the module
    • getNumber

      public final int getNumber()
      Returns the number.
      Returns:
      the number
    • getString

      public final String getString()
      Returns the written form of this error code.

      It is a combination of the product, module and number part, separated by a "-"-character, f.e. "JCR-4711" or "ECM-TPS-42"

      If used in a BaseException, this written form is the resource key used for localization.

      Returns:
      the written form of this error code.
    • toString

      public String toString()
      Overrides:
      toString in class Object