How to catch all uncaught errors in a dart polymer app?

亡梦爱人 提交于 2019-11-28 10:50:04

问题


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?


回答1:


How about using Window.onError.

import 'dart:html';

main() {
  window.onError.listen((ErrorEvent e) => print(e.message));
  throw 'boom!';
}



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!