-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please don't use toString when printing NoSuchMethodException #546
Comments
This is also confusing: class Fisk { main() { NoSuchMethodException - receiver: 'Instance of 'Object'' function name: 'toString' arguments: []] |
To understand better what Peter means with his second example from comment 1: main() { produces Unhandled exception: Note that the parameter is printed here. Maybe we should also print the class name of the parameter or the position of the parameter, such as: I assume this will be revised when we address the general problems of NoSuchMethod handling. |
Issue #420 has been merged into this issue. |
Set owner to @sgmitrovic. |
Is this still valid? |
I think this bug is still valid. The error message is slightly different (as in much better): NoSuchMethodException : method not found: 'addFromInteger' The information I would like to have in the first part is the classes of the receiver and arguments, for example: NoSuchMethodException : method not found: 'addFromInteger' Also, if toString is broken, it hides the original exception: Unhandled exception: In addition, there is no stack trace for the broken toString method. Here is one possible solution to this problem: Add a private helper method to Object: String _toExceptionString() { Override this method in String, int, and double implementations. For example, in Smi: String _toExceptionString() => 'int(${toString()})'; |
Added this to the M2 milestone. |
Is this still valid, I think this has been fixed by library team. |
I fixed this in r12533. Set owner to @peter-ahe-google. |
It would be nice if the VM would tell me the class name, not the result of calling toString when throwing a NoSuchMethodException.
Otherwise, things like this is hard to debug:
class Fisk {
toString() => "1";
}
class Hest {
toString() { throw "hest"; }
}
main() {
try {
1 + new Fisk();
} catch (var e) {
print(e);
}
1 + new Hest();
}
Right now the VM says:
NoSuchMethodException - receiver: '1' function name: 'addFromInteger' arguments: [1]]
Unhandled exception:
<Received exception while converting exception to string>
0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:315 col:3
1. Function: 'IntegerImplementation.+' url: 'bootstrap_impl' line:1463 col:32
2. Function: '::.main' url: '/Users/ahe/Dart/all/dart.googlecode.com/dart/frog/fisk.dart' line:15 col:5
These examples are silly, but very similar issues are making it hard to debug problems in Frog/Leg.
The text was updated successfully, but these errors were encountered: