avoid-throw-objects-without-tostring
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 {
// LINT: Avoid throwing objects that do not implement the 'toString' method.
throw MyException();
}
}
class MyException {}
✅ Good:
void function() {
try {
// ...
} on Object {
throw MyException();
}
}
class MyException {
String toString() => ...;
}