throws 1.0.0-alpha.2 copy "throws: ^1.0.0-alpha.2" to clipboard
throws: ^1.0.0-alpha.2 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('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<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