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.下一节将介绍如何捕捉异常。
#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.下一节将介绍如何捕捉异常。
相关文章推荐
- iOS开发者账号添加子账号
- 软考-分治算法
- 特征选择方法-信息增益
- ListView的基础应用
- 比较经典的Jquery代码
- Linux tty1(ctrl+alt+f1)上下滚屏
- 48.Linked List Cycle II
- 【原创】Mac上编译Hadoop1.0.3出现的一些问题
- 8_20 文件解释器
- 047.@try…@catch... 捕捉异常
- 每天被面试虐一点点(三) int (*(*F)(int, int))(int)
- JSP学习笔记(一)
- Makefile有三个非常有用的变量。分别是$@,$^,$<代表的意义分别是:
- MagicalRecord数据库查看工具
- 创建jQuery插件示例
- 048.@throw 自定义异常
- git安装教程和使用方法记录
- 【随机过程】随机过程之泊松过程的直观理解
- Android把view的画面转换为bitmap
- 函数式编程--lambda表达式对比匿名内部类