Skip to main content

avoid-throw-objects-without-tostring

added in: 1.4.0
preset: recommended

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() => ...;
}