throws 1.0.0-alpha.5 copy "throws: ^1.0.0-alpha.5" to clipboard
throws: ^1.0.0-alpha.5 copied to clipboard

An annotation for documenting and enforcing throwing functions.

throws #

Annotations for documenting and enforcing throwing functions.

Install #

Add the dependency to your pubspec.yaml.

Usage #

Annotate functions that can throw:

@Throws(reason: 'Parsing input failed', errors: {FormatException, RangeError})
int parsePositiveInt(String input) {
  final value = int.parse(input);
  if (value < 0) {
    throw RangeError('Value must be non-negative');
  }
  return value;
}

You can also use the shorthand constant:

@throws
void mightThrow() {
  throw Exception('x');
}

Expected errors #

Use errors to declare the error types callers should handle. This is a set of Type literals.

@Throws(reason: 'Reason', errors: {StateError})
int singleValue(Iterable<int> values) => values.single;
3
likes
0
points
402
downloads

Publisher

verified publisherfeduke-nukem.dev

Weekly Downloads

An annotation for documenting and enforcing throwing functions.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on throws