avoid-throw-objects-without-tostring
added in: 1.4.0
warning
Warns when a thrown object does not implement toString
.
Objects that do not have an implemented toString
method will be represented as "Instance of ..." when serialized.
Example
❌ Bad:
void function() {
try {
// ...
} on Object {
throw MyException(); // LINT
}
}
class MyException {}
✅ Good:
void function() {
try {
// ...
} on Object {
throw MyException();
}
}
class MyException {
String toString() => ...;
}