Instance Method

failWithError:

Signals to this coder that the decode operation has failed.

Declaration

- (void)failWithError:(NSError *)error;

Parameters

error

An error that indicates why decoding failed.

Discussion

Typically, you call this method in your initWithCoder: implementation. You should set the error when you detect problems such as lack of secure coding, data corruption, or a domain validation failure.

This method is only meaningful to call for decodes.

The effect of calling this method depends on the value of decodingFailurePolicy, as follows:

  • If the policy is NSDecodingFailurePolicyRaiseException, calling this method throws an exception immediately. Swift code cannot catch this kind of exception.

  • If the policy is NSDecodingFailurePolicySetErrorAndReturn, calling this method sets the error property once per call to one of the decode methods. Calling it repeatedly has no effect until the call stack unwinds to one of these methods’ entry points.

See Also

Managing Decode Errors

error

An error in the top-level encode.