Skip to content

Commit

Permalink
Add ArgumentError.checkNotNull utility
Browse files Browse the repository at this point in the history
In the places where other utilities like `RangeError.checkNotNegative`
are used it reads nicer to call through a similar signature than to
follow a conditional with the utility.

Change-Id: Idd89b2934020fb55e57a22c39773fd7879d1c28f
Reviewed-on: https://dart-review.googlesource.com/c/81287
Commit-Queue: Nate Bosch <[email protected]>
Reviewed-by: Lasse R.H. Nielsen <[email protected]>
  • Loading branch information
natebosch authored and [email protected] committed Oct 24, 2018
1 parent 0170b8d commit 655310d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ a InstanceTypeError if the instance isn't of the class expected
### Core library changes

* Add `HashMap.fromEntries` and `LinkedHashmap.fromEntries` constructors.
* Add `ArgumentError.checkNotNull` utility method.

### Dart VM

Expand Down
7 changes: 7 additions & 0 deletions sdk/lib/core/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ class ArgumentError extends Error {
message = "Must not be null",
invalidValue = null;

/**
* Throws if [argument] is `null`.
*/
static void checkNotNull(Object argument, [String name]) {
if (argument == null) throw ArgumentError.notNull(name);
}

// Helper functions for toString overridden in subclasses.
String get _errorName => "Invalid argument${!_hasValue ? "(s)" : ""}";
String get _errorExplanation => "";
Expand Down

0 comments on commit 655310d

Please sign in to comment.