Design Patterns Handbook
  • Introduction
  • Creational Patterns
    • Builder
    • Factory
    • Abstract Factory
    • Factory Method
    • Prototype
    • Singleton
    • Object Pool
    • Revealing Constructor
  • Structural Patterns
    • Adapter
    • Composite
    • Proxy
    • Flyweight
    • Facade
    • Bridge
    • Decorator
    • Private Class Data
  • Behavioral Patterns
    • Template Method
    • Mediator
    • Chain Of Responsibility
    • Observer
    • Strategy
    • Command
    • State
    • Visitor
    • Memento
    • Interpreter
    • Null Object
    • Iterator
    • Middleware
  • Clean Code Patterns
    • Extract Method
    • Clarify Responsibility
    • Remove Duplications
    • Keep Refactoring
    • Always Unit Test
    • Create Data Type
    • Comment to Better Name
    • Consistent Naming
    • If-else over ternary operator
    • Composition over Inheritance
    • Too Many Returns
    • Private to Interface
  • Anti Patterns
    • Big Ball of Mud
    • Singleton
    • Mad Scientist
    • Spaghetti Code
    • It Will Never Happen
    • Error Codes
    • Commented Code
    • Abbreviations
    • Prefixes
    • Over Patternized
    • Generic Interface over Function
Powered by GitBook
On this page

Was this helpful?

  1. Anti Patterns

Error Codes

When the error codes escape from a system to clients, then they are supposed to find the solution based on the code. Forcing users to decrypt error code and find a solution is very irritating.

public class ExceptionErrorCodes {

    public static final int FIELD_MUST_BE_EMPTY = 101;

    public static final int FIELD_MUST_NOT_BE_EMPTY = 102;

    public static final int CANNOT_RETRIEVE_TASK = 103;

    public static final int FIELD_CANNOT_BE_MODIFIED = 104;

    public static final int MYBATIS_EXCEPTION = 103;

    public static final int CSV_INVALID_FIELD_EXCEPTION = 104;

    public static final int CSV_NO_HEADER_FOUND_EXCEPTION = 105;

    public static final int FILE_UPLOAD_EXCEPTION = 107;

    public static final int CATCHALL_EXCEPTION = 999;
}
PreviousIt Will Never HappenNextCommented Code

Last updated 5 years ago

Was this helpful?