// In traditional manner
//
if (id == null) {
throw new NullPointerException(“Id can’t be null”);
}
Assert.notNull(id, “Id can’t be null”); // Spring framework Assert API
Validate.notNull(id, “Id can’t be null”); // Apache Commons Validate API
Contract.Requires<NullReferenceException>(id != null, “Id can’t be null”); // Code Contracts .NET framework
- Java Libraries vis-a-vis API
- Google Guava – Preconditions
- Spring framework – Assert
- Apache Commons – Validate
- .NET framework vis-a-vis API
- Code Contracts – Contract
- Check for validation of methods’ arguments. Throws exception such as IllegalArgumantException or the equivalent upon failure.
- Check whether a specific value is not null. Throws exception such as NullPointerException or the equivalent upon failure.
- Check state of the object. Throws exception such as IllegalStateException or the equivalent upon failure
- Check whether the index is a valid element or position index into a list, string, or array with the specified size. An element index may range from 0 inclusive to size exclusive. Throws exception such as IndexOutOfBoundsException or the equivalent upon failure
- Neural Network & Multi-layer Perceptron Examples - March 21, 2023
- K-Fold Cross Validation – Python Example - March 21, 2023
- Positively Skewed Probability Distributions: Examples - March 21, 2023
Leave a Reply