Constructs a new InvalidInstanceOfError with the specified key and
expected instance type.
The name of the key with the invalid instance.
The expected class or constructor name.
OptionalcauseOptionalstackStatic OptionalprepareOptional override for formatting stack traces
Staticstack
The
InvalidInstanceOfErroris thrown when a value associated with a key is not an instance of the expected class or constructor.This error is useful when checking for object instances (e.g.,
Date,File) and enforcing that the value matches the expected class.Example