当从MySql截取错误时,事先不知道传递给我的错误类的内容是什么。所以我编码:
.catchError((firstError) {
sqlMessage = firstError.message;
try {
sqlError = firstError.osError;
} catch (noInstanceError){
sqlError = firstError.sqlState;
}
});在这种情况下,我想知道e是否包含实例变量osError或sqlState,因为其中任何一个都包含特定的错误代码。总的来说(为了提高我的知识),是否有可能编写类似if (firstError.instanceExists(osError)) ...的东西,以及如何编写?
发布于 2014-02-23 20:43:30
这应该是你想做的事:
import 'dart:mirrors';
...
// info about the class declaration
reflect(firstError).type.declarations.containsKey(#osError);
// info about the current instance
var m = reflect(firstError).type.instanceMembers[#osError];
var hasOsError = m != null && m.isGetter;发布于 2014-02-24 19:53:37
https://stackoverflow.com/questions/21974178
复制相似问题