在 Flutter 中 throw Exception('message') 与 throw 'message' 之间有什么实际区别吗?
Is there any practical difference between throw Exception('message') vs throw 'message' in Flutter?
使用之间有什么实际区别吗:
throw Exception('message');
对
throw 'message';
什么时候想在flutter中抛出错误?
throw 'message'
抛出 String
.
试图抓住它的呼叫者需要做:
try {
throw 'message';
} on String catch (s) {
...
}
或者需要使用一揽子的、未键入的 catch
子句(which isn't recommended). Doing this would be very unusual and would not be behavior callers would expect. There is an only_throw_errors
lint 对此发出警告。
throw Exception('message');
抛出构造的 Exception
对象。这更典型。
使用之间有什么实际区别吗:
throw Exception('message');
对
throw 'message';
什么时候想在flutter中抛出错误?
throw 'message'
抛出 String
.
试图抓住它的呼叫者需要做:
try {
throw 'message';
} on String catch (s) {
...
}
或者需要使用一揽子的、未键入的 catch
子句(which isn't recommended). Doing this would be very unusual and would not be behavior callers would expect. There is an only_throw_errors
lint 对此发出警告。
throw Exception('message');
抛出构造的 Exception
对象。这更典型。