iOS Guides | Samples

MonoTouch.Foundation.NSError Class

Encapsulates an error.

See Also: NSError

Syntax

[MonoTouch.Foundation.Register("NSError", true)]
public class NSError : NSObject, INSCopying, INSSecureCoding, IDisposable

Remarks

NSError objects wrap both error domains, an error code and an optional error payload into one.   The error domain is used to classify the error (typically, there is an error domain per susbsystem).   There are several static properties in the NSError class that represent some common domains like the NSError.CocoaErrorDomain or the NSError.CFNetworkErrorDomain.

NSErrors can be serialized.

You can create an NSError with a domain by providing both parameters.  The following example shows how to do this, and passes a payload:

C# Example

var payload = NSDictionary.FromObjectsAndKeys (new object [] {1,2,3,4});

When creating the error with a payload, you can provide a number of optional elements that provide the user with more information.   You should provide this information on the NSDictionary with the keys defined in this class like NSError.LocalizedErrorKeyNSError.FilePathErrorKey, Foundation.HelpAnchorErrorKeyNSError.LocalizedDescriptionKeyNSError.LocalizedFailureReasonErrorKeyNSError.LocalizedREcoveryOptionsErrorKeyNSError.LocalizedRecoverySuggestionErrorKeyNSError.StringEncodingErrorKey, NSError.UnderlyingErrorKey and MonoTouch.Foundation.NSError.UrlErrorKey.

For example:

C# Example

var userInfo = new NSDictionary (NSError.LocalizedDescriptionKey, "Error while parsing GeoJSON”);

The LocalizedDescription property will return the above value.

Related content

Requirements

Namespace: MonoTouch.Foundation
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.Foundation.NSError are listed below.

See Also: NSObject

Public Constructors

Do not use the Default Constructor unless you are dealing with a low-level API that will initialize the object for you.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.
A constructor that initializes the object with a specified domain and an error code.
A constructor that initializes the object with a specified domain, an error code and a payload in the form of a dictionary.

Public Properties

[read-only]
static
CFNetworkErrorDomainNSString. The CFNetwork error domain.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
[read-only]
static
CocoaErrorDomainNSString. The Cocoa error domain.
[read-only]
CodeInt32. The error code in this NSError
[read-only]
static
CoreLocationErrorDomainNSString. The CoreLocation error domain.
[read-only]
static
CoreMotionErrorDomainNSString. The CoreMotion error domain.
[read-only]
DomainString. The domain associated with this error.
[read-only]
static
EABluetoothAccessoryPickerErrorDomainNSString. Represents the value associated with the constant EABluetoothAccessoryPickerErrorDomain
[read-only]
static
FilePathErrorKeyNSString. Standard key to use in the userInfo payload for associating a file path with the error.
[read-only]
HelpAnchorString. Returns the help anchor that was associated with this error (the payload contained a HelpAnchorErrorKey)
[read-only]
static
HelpAnchorErrorKeyNSString. Standard key to use in the userInfo payload for associating a hint to provide to the user.
[read-only]
LocalizedDescriptionString. Returns a localized description of the error.
[read-only]
static
LocalizedDescriptionKeyNSString. Standard key to use in the userInfo payload for associating a localized description of the problem to provide to the user.
[read-only]
LocalizedFailureReasonString.
[read-only]
static
LocalizedFailureReasonErrorKeyNSString. Represents the value associated with the constant NSLocalizedFailureReasonErrorKey
[read-only]
LocalizedRecoveryOptionsString[].
[read-only]
static
LocalizedRecoveryOptionsErrorKeyNSString. Represents the value associated with the constant NSLocalizedRecoveryOptionsErrorKey
[read-only]
LocalizedRecoverySuggestionString.
[read-only]
static
LocalizedRecoverySuggestionErrorKeyNSString. Represents the value associated with the constant NSLocalizedRecoverySuggestionErrorKey
[read-only]
static
MachErrorDomainNSString. Represents the value associated with the constant NSMachErrorDomain
[read-only]
static
MapKitErrorDomainNSString. Represents the value associated with the constant MKErrorDomain
[read-only]
static
NSNetServicesErrorDomainNSString. Represents the value associated with the constant NSNetServicesErrorDomain
[read-only]
static
NSStreamSocketSSLErrorDomainNSString. Represents the value associated with the constant NSStreamSocketSSLErrorDomain
[read-only]
static
NSStreamSOCKSErrorDomainNSString. Represents the value associated with the constant NSStreamSOCKSErrorDomain
[read-only]
static
NSUrlErrorDomainNSString. Represents the value associated with the constant NSURLErrorDomain
[read-only]
static
OsStatusErrorDomainNSString. Represents the value associated with the constant NSOSStatusErrorDomain
[read-only]
static
PosixErrorDomainNSString. Represents the value associated with the constant NSPOSIXErrorDomain
[read-only]
static
RecoveryAttempterErrorKeyNSString. Represents the value associated with the constant NSRecoveryAttempterErrorKey
[read-only]
static
StringEncodingErrorKeyNSString. Represents the value associated with the constant NSStringEncodingErrorKey
[read-only]
static
UnderlyingErrorKeyNSString. Represents the value associated with the constant NSUnderlyingErrorKey
[read-only]
static
UrlErrorKeyNSString. Represents the value associated with the constant NSURLErrorKey
[read-only]
UserInfoNSDictionary. Returns the associated user-defined payload.
[read-only]
static
WatchKitErrorDomainNSString. The WatchKit error domain.

Public Methods

Copy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.
static
FromDomain(NSString, Int32) : NSError
Creates an NSError instance from a given domain and code.
static
FromDomain(NSString, Int32, NSDictionary) : NSError
Creates an NSError instance from a given domain, code and a user-defined payload in the form of an NSDictionary.
static
GetUserInfoValueProvider(String) : NSErrorUserInfoValueProvider
static
SetUserInfoValueProvider(String, NSErrorUserInfoValueProvider)
override
ToString() : String
Returns a string representation of the value of the current instance.