菜鸟教程小白 发表于 2022-12-13 03:59:06

ios - NSException 派生类或异常名称的列表?


                                            <p><p>我已经通过 <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Exceptions/Exceptions.html" rel="noreferrer noopener nofollow">Introduction to Exception Programming Topics for Cocoa</a> .在 <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Exceptions/Tasks/RaisingExceptions.html" rel="noreferrer noopener nofollow">Throwing Exceptions</a> 下,显示了一个异常名称:<code>FileNotFoundException</code>:</p>

<pre><code>NSException *e = [NSException
    exceptionWithName:@&#34;FileNotFoundException&#34;
               reason:@&#34;File Not Found on System&#34;
             userInfo:nil];

@throw e;
</code></pre>

<p>但是,<a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Exceptions/Concepts/PredefinedExceptions.html" rel="noreferrer noopener nofollow">Predefined Exceptions</a>页面列出了大约 10 个异常,<code>FileNotFoundException</code> 没有列出。</p>

<p>在哪里可以找到常见或预期的异常和名称列表?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这很奇怪,这些是我看到的在 NSExcpetion.h 中定义的唯一常量:</p>

<pre><code>FOUNDATION_EXPORT NSString * const NSGenericException;
FOUNDATION_EXPORT NSString * const NSRangeException;
FOUNDATION_EXPORT NSString * const NSInvalidArgumentException;
FOUNDATION_EXPORT NSString * const NSInternalInconsistencyException;

FOUNDATION_EXPORT NSString * const NSMallocException;

FOUNDATION_EXPORT NSString * const NSObjectInaccessibleException;
FOUNDATION_EXPORT NSString * const NSObjectNotAvailableException;
FOUNDATION_EXPORT NSString * const NSDestinationInvalidException;

FOUNDATION_EXPORT NSString * const NSPortTimeoutException;
FOUNDATION_EXPORT NSString * const NSInvalidSendPortException;
FOUNDATION_EXPORT NSString * const NSInvalidReceivePortException;
FOUNDATION_EXPORT NSString * const NSPortSendException;
FOUNDATION_EXPORT NSString * const NSPortReceiveException;

FOUNDATION_EXPORT NSString * const NSOldStyleException;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - NSException 派生类或异常名称的列表?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18564364/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18564364/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - NSException 派生类或异常名称的列表?