我有一个<core-icon>
元素
<polymer-element name="app-element">
<template>
<core-icon icon="{{icon}}"></core-icon>
</template>
<script ...>
</polymer-element>
@CustomTag('app-element')
class AppElement extends PolymerElement {
AppElement.created() : super.created();
@observable
String icon = 'menu';
clickHandler(e) {
icon = null;
}
}
这导致了这个异常
Exception caught during observer callback: TypeError: Cannot read property 'split' of null
at core-icon.Polymer.updateAlt (http://localhost:63342/core-elements/packages/core_elements/src/core-icon/core-icon.html:188:50)
at core-icon.Polymer.updateIcon (http://localhost:63342/core-elements/packages/core_elements/src/core-icon/core-icon.html:147:14)
at core-icon.g.invokeMethod (http://localhost:63342/core-elements/packages/polymer/src/js/polymer/polymer.js:13:25932)
at core-icon.g.notifyPropertyChanges (http://localhost:63342/core-elements/packages/polymer/src/js/polymer/polymer.js:13:24037)
at Object.x.report_ (http://localhost:63342/core-elements/packages/polymer/src/js/polymer/polymer.js:12:18274)
at Object.S.check_ (http://localhost:63342/core-elements/packages/polymer/src/js/polymer/polymer.js:12:22612)
at c (http://localhost:63342/core-elements/packages/polymer/src/js/polymer/polymer.js:12:12181) polymer.concat.js:4861x.report_ polymer.concat.js:4861S.check_ polymer.concat.js:5264c
在我看来,这是一个<core-icon>
问题,我将提出一个问题,但无论如何我的问题是:
有没有办法在 Dart 中捕获这样的 JavaScript 异常?
我当然试图icon = null;
用成功try/catch
或失败来换行window.onError.listen((e)...);
。