throws 1.0.0-alpha
throws: ^1.0.0-alpha copied to clipboard
An annotation for documenting and enforcing throwing functions.
[throws]
throws #
Annotations for documenting and enforcing throwing functions.
Install #
Add the dependency to your pubspec.yaml.
Usage #
Annotate functions that can throw:
@Throws('Parsing input failed', {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'); }
expectedErrors #
Use expectedErrors to declare the error types callers should handle. This is a set of Type literals.
@Throws('Reason', {StateError}) int singleValue(Iterable