uncaughtExceptionHandler

uncaughtExceptionHandler

This question already has answers here:
Register UncaughtExceptionHandler in Objective C using NSSetUncaughtExceptionHandler
                                
                                    (3个答案)
                                
                        
                                6年前关闭。
            
                    
我在我的AppDelegate.m中使用以下代码片段来捕获异常:

void uncaughtExceptionHandler(NSException *exception)
{
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
}


如何避免此警告:

Semantic Issue: No previous prototype for function 'uncaughtExceptionHandler'?

最佳答案

只需在.h文件中声明此方法

void uncaughtExceptionHandler(NSException * exception);

或将此函数放在调用函数上。

    void uncaughtExceptionHandler(NSException *exception){
       //your code
    }

-

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

            NSSetUncaughtExceptionHandler(&HandleExceptions);
//your code

return YES;

}

10-06 11:05