Throws class
Used to annotate getters, methods, functions, parameters or local variables that can throw an exception (or multiple exceptions/errors) and therefore an invocation of such declarations must explicitly handle that exception.
The intention of this annotation is to help avoid unhandled exceptions.
For example:
@Throws()
void fn() { /* ... */ }
@Throws({IndexError})
void anotherFn() { /* ... */ }
void main() {
try {
fn(); // OK.
} catch(_) {}
fn(); // LINT.
try {
anotherFn(); // OK.
} catch(_) {}
try {
anotherFn(); // LINT.
} on Exception catch(_) {}
}
DCM will provide feedback if
- an invocation of a declaration with this annotation has unhandled exceptions
- a declaration is not marked with this annotation, but can throw an exception
- a declaration is marked with this annotation, but does not have any invocation that throws an exception
For more information, see the documentation for "handle-throwing-invocations" and "prefer-correct-throws".
Constructors
Properties
-
expectedErrors
→ Set<
Type> ? -
The types of errors or exceptions which the annotated declaration can throw.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited