Skip to content

Files

Latest commit

 

History

History
31 lines (23 loc) · 704 Bytes

only_throw_errors.md

File metadata and controls

31 lines (23 loc) · 704 Bytes

Pattern: Throwing instance that does not extend Error/Exception

Issue: -

Description

DO throw only instances of classes that extend dart.core.Error or dart.core.Exception.

Throwing instances that do not extend Error or Exception is a bad practice; doing this is usually a hack for something that should be implemented more thoroughly.

Example of incorrect code:

void throwString() {
 throw 'hello world!'; // LINT
}

Example of correct code:

void throwArgumentError() {
 Error error = new ArgumentError('oh!');
 throw error; // OK
}

Further Reading