ArgumentError

当函数接收了不可接受的参数时抛出错误。

方法应该记录它接受的参数的限制,例如,如果整数参数必须是非空的,字符串参数必须非空,或者动态类型参数必须实际具有几种接受的类型之一。

用户应该能够预测哪些参数会导致抛出错误,并避免使用这些参数调用。

通常最好将不可接受的值作为错误的一部分提供,以帮助用户找出问题所在,因此,使用 ArgumentError.value 构造函数是首选。只有在某些原因下无法提供值时才应使用 ArgumentError.new

继承
实现者

构造函数

ArgumentError([dynamic message, @Since("2.14") String? name])
创建一个带有 message 的错误,描述参数的问题。
ArgumentError.notNull([String? name])
创建一个必须非空的 null 参数的参数错误。
ArgumentError.value(dynamic value, [String? name, dynamic message])
创建包含无效 value 的错误。

属性

hashCode int
此对象的哈希码。
no setterinherited
invalidValue → dynamic
无效的值。
final
message → dynamic
描述问题的消息。
final
name String?
无效参数的名称(如果有的话)。
final
runtimeType Type
对象运行时类型的表示。
no setterinherited
stackTrace StackTrace?
第一次抛出此错误时的堆栈跟踪。
no setterinherited

方法

noSuchMethod(Invocation invocation) → dynamic
当访问不存在的方法或属性时调用。
inherited
toString() String
该对象的字符串表示形式。
重写

运算符

operator ==(Object other) bool
等号运算符。
inherited

静态方法

checkNotNull<@Since("2.8") T>(T? argument, [String? name]) → T
如果 argumentnull,则抛出异常。