avoid-throw-objects-without-tostring
preset: recommended
Warns when a thrown object does not implement toString
.
Objects that do not implement the toString
method will be represented as "Instance of ..." when serialized.
Example
❌ Bad:
void function() {
try {
// ...
} on Object {
throw MyException(); // LINT: Avoid throwing objects that do not implement the 'toString' method.
}
}
class MyException {}
✅ Good:
void function() {
try {
// ...
} on Object {
throw MyException();
}
}
class MyException {
String toString() => ...;
}