Skip to content

Error Handling #31

@jnguyen095

Description

@jnguyen095
  1. Use Exceptions Rather Than Return Codes
  2. Write Your Try-Catch-Finally Statement First
  3. Use Unchecked Exceptions
  4. Provide Context with Exceptions
  5. Define Exception Classes in Terms of a Caller’s Needs
  6. Don’t Return Null, if null return an empty collection
public List<Employee> getEmployees() {
    if( .. there are no employees .. )
      return Collections.emptyList();
}
  1. Don’t Pass Null
public double xProjection(Point p1, Point p2) {
    if (p1 == null || p2 == null) {
      throw InvalidArgumentException(
        "Invalid argument for MetricsCalculator.xProjection");
    }
    return (p2.xp1.x) * 1.5;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions