Class: NSError

Inherits:
NSObject show all

Overview

An NSError object encapsulates richer and more extensible error information than is possible using only an error code or error string. The core attributes of an NSError object are an error domain (represented by a string), a domain-specific error code and a user info dictionary containing application specific information.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) errorWithDomain(domain, code:code, userInfo:dict)

Creates and initializes an NSError object for a given domain and code with a given userInfo dictionary.

Parameters:

  • domain (String)

    The error domain—this can be one of the predefined NSError domains, or an arbitrary string describing a custom domain. domain must not be nil. See “Error Domains” for a list of predefined domains.

  • code (Integer)

    The error code for the error.

  • dict (Hash)

    The userInfo dictionary for the error. userInfo may be nil.

Returns:

  • (Object)

    An NSError object for domain with the specified error code and the dictionary of arbitrary data userInfo.

Instance Method Details

- (Integer) code

Returns the receiver’s error code. Note that errors are domain specific.

Returns:

  • (Integer)

    The receiver’s error code.

- (String) domain

Returns the receiver’s error domain.

Returns:

  • (String)

    A string containing the receiver’s error domain.

- (String) helpAnchor

A string to display in response to an alert panel help anchor button being pressed. If this method returns a non-nil value for an error being presented by alertWithError:, the alert panel will include a help anchor button that can display this string.The best way to get a value to return for this method is to specify it as the value of NSHelpAnchorErrorKey in the NSError object’s userInfo dictionary; or the method can be overridden.

Returns:

  • (String)

    An NSString that the alert panel will include a help anchor button with that value.

- (Object) initWithDomain(domain, code:code, userInfo:dict)

Returns an NSError object initialized for a given domain and code with a given userInfo dictionary. This is the designated initializer for NSError.

Parameters:

  • domain (String)

    The error domain—this can be one of the predefined NSError domains, or an arbitrary string describing a custom domain. domain must not be nil. See “Error Domains” for a list of predefined domains.

  • code (Integer)

    The error code for the error.

  • dict (Hash)

    The userInfo dictionary for the error. userInfo may be nil.

Returns:

  • (Object)

    An NSError object initialized for domain with the specified error code and the dictionary of arbitrary data userInfo.

- (String) localizedDescription

Returns a string containing the localized description of the error. This method can be overridden by subclasses to present customized error strings.

Returns:

  • (String)

    A string containing the localized description of the error.By default this method returns the object in the user info dictionary for the key NSLocalizedDescriptionKey. If the user info dictionary doesn’t contain a value for NSLocalizedDescriptionKey, a default string is constructed from the domain and code.

- (String) localizedFailureReason

Returns a string containing the localized explanation of the reason for the error. This method can be overridden by subclasses to present customized error strings.

Returns:

  • (String)

    A string containing the localized explanation of the reason for the error. By default this method returns the object in the user info dictionary for the key NSLocalizedFailureReasonErrorKey.

- (Array) localizedRecoveryOptions

Returns an array containing the localized titles of buttons appropriate for displaying in an alert panel. The first string is the title of the right-most and default button, the second the one to the left of that, and so on. The recovery options should be appropriate for the recovery suggestion returned by localizedRecoverySuggestion. If the user info dictionary doesn’t contain a value for NSLocalizedRecoveryOptionsErrorKey, only an OK button is displayed.This method can be overridden by subclasses to present customized recovery suggestion strings.

Returns:

  • (Array)

    An array containing the localized titles of buttons appropriate for displaying in an alert panel. By default this method returns the object in the user info dictionary for the key NSLocalizedRecoveryOptionsErrorKey. If the user info dictionary doesn’t contain a value for NSLocalizedRecoveryOptionsErrorKey, nil is returned.

- (String) localizedRecoverySuggestion

Returns a string containing the localized recovery suggestion for the error. The returned string is suitable for displaying as the secondary message in an alert panel. This method can be overridden by subclasses to present customized recovery suggestion strings.

Returns:

  • (String)

    A string containing the localized recovery suggestion for the error. By default this method returns the object in the user info dictionary for the key NSLocalizedRecoverySuggestionErrorKey. If the user info dictionary doesn’t contain a value for NSLocalizedRecoverySuggestionErrorKey, nil is returned.

- (Object) recoveryAttempter

Returns an object that conforms to the NSErrorRecoveryAttempting informal protocol. The recovery attempter must be an object that can correctly interpret an index into the array returned by localizedRecoveryOptions.

Returns:

  • (Object)

    An object that conforms to the NSErrorRecoveryAttempting informal protocol. By default this method returns the object for the user info dictionary for the key NSRecoveryAttempterErrorKey. If the user info dictionary doesn’t contain a value for NSRecoveryAttempterErrorKey, nil is returned.

- (Hash) userInfo

Returns the receiver's user info dictionary.

Returns:

  • (Hash)

    The receiver's user info dictionary, or nil if the user info dictionary has not been set.