您的位置:首页 > 其它

046.@try 处理异常

2015-10-27 16:01 176 查看
---------------  FKEatable.h  ---------------

#import <Foundation/Foundation.h>
@protocol FKEatable
@optional

-(void) taste;

@end

---------------  FKApple.h  ---------------

#import "FKEatable.h"
@interface FKApple : NSObject <FKEatable>

@end

---------------  FKApple.m  ---------------

#import "FKApple.h"
@implementation FKApple

@end

---------------  main.m  ---------------

#import <Foundation/Foundation.h>

#import "FKApple.h"
int main()

{

    FKApple* app = [[FKApple alloc] init];

    [app taste];

}

一、运行以上代码会出现如下错误:

 -[FKApple taste]: unrecognized selector sent to instance 0x10030e540

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FKApple taste]: unrecognized selector sent to instance 0x10030e540'

二、本节代码涉及到的知识点:

1.错误原因:FKEateble协议中的taste方法没有实现。

2.下一节将介绍如何捕捉异常。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: