Tip #17 – Return informative and actionable exceptions from reusable assets
Reusable assets such as service capabilities need to return both technical and business (or domain relevant) exceptions. If a service or component returns a business exception often times it is useful to provide additional information to resolve the exception as well. Similarly, if a business exception needs a human user to resolve (e.g. fixing incorrect data, overriding a business rule, escalating to a manager based on business rules) you will want to return this information. It signals to the consumer that repeatedly invoking the call won’t resolve the problem.
Exceptions must follow a standard format that provides information for two audiences – internal support team and your external consumer. They should include warnings, statuses, remedial steps, retry procedure in addition to the core exception (if applicable). From a reusable asset standpoint, consistent exceptions signal robustness. It is critical for your consumers to know that the asset returns high quality exceptions and handles them gracefully. For your internal support staff, you should add additional diagnostic information such as stack trace, location of exception, state of key variables, as well as possible resolutions to the problem. For reusable services, this could make the difference between successfully recovering due to a failure and missing a key consumer’s SLA requirements. In other words, your exceptions need to be as informative and actionable as possible.