I want to put in a handler that will catch all unhandled errors in a Polymer app.
I figured Zone
would be the trick so tried
void main() {
runZoned(() => initPolymer(), onError: (e, stackTrace) {
_log.shout('TOP ZONE', e, stackTrace);
});
}
But that doesn't work. The errors never get to this error handler.
Not sure if this relates to http://code.google.com/p/dart/issues/detail?id=15854
How do people handle this?
How about using Window.onError.
import 'dart:html';
main() {
window.onError.listen((ErrorEvent e) => print(e.message));
throw 'boom!';
}
So I know we have gotten error handling to work using the following construct:
runZoned(() {
return initPolymer().run(() => Polymer.onReady
.then(doSomeStuff)
.whenComplete(doSomeCompleting));
},
onError: (err, [stackTrace]) {
logger.severe("Received an error", err, stackTrace);
});
I have posted it in the interest of helping you quickly. I dont have a great explanation off the top of my head why your version isn't working at the moment. Ill do some digging and see if I can work out what is really different.
来源:https://stackoverflow.com/questions/28549222/how-to-catch-all-uncaught-errors-in-a-dart-polymer-app