Objective-C:异常的处理
//
// main.m
// 03-动态绑定
//
// Created by mac on 15/8/11.
// Copyright (c) 2015年. All rights reserved.
// #import <Foundation/Foundation.h>
#import "Fraction.h"
#import "Complex.h"
#import "MyException.h"
int main(int argc, const char * argv[])
{
@autoreleasepool
{
//测试分数类
Fraction *f1 = [[Fraction alloc]initWithNumerator:
addDenominator:];
[f1 print]; Fraction *f2 = [[Fraction alloc]initWithNumerator:
addDenominator:];
[f2 print]; Fraction *f3 = [f1 add:f2];
[f3 print]; //测试复数类
Complex *c1 = [[Complex alloc]initWithReal:5.0 andImag:3.0];
[c1 print]; Complex *c2 = [[Complex alloc]initWithReal:4.3 andImag:2.5];
[c2 print]; Complex *c3 = [c1 add: c2];
[c3 print]; //测试动态绑定
id pObj = nil;
pObj = f3;
[f3 print]; pObj = c3;
[c3 print]; MyException *pe;
@try//将容易出现异常的代码放在try代码块里面
{
id arr[] = {c1,f1,@""};
for(int i=;i<;i++)
{
[arr[i] print];
pe = [[MyException alloc] initWithName:@"MyException" reason:@"test" userInfo:nil];
@throw pe;//主动抛出自定义的异常
}
NSLog(@"try last statement");//在出现异常后会跳过@try中后续的代码,不会执行。
}
@catch(MyException *e)//捕捉自定义的异常
{
NSLog(@"MyException:%@",[e reason]);
}
@catch(NSException *e)//系统捕捉异常
{
NSLog(@"%@",[e reason]);
}
@finally//最终处理
{
NSLog(@"finally");
}
//异常处理完,后续代码会继续执行
NSLog(@"last statement!");
}
return ;
}
Objective-C:异常的处理的更多相关文章
- Swift 使用 LLDB 调试命令
swift 和 oc 的语法不一样: Xcode 调试技巧之 Swift 篇 打印和赋值,观察数值变量和view对象属性 p指令可打印其对象类型.内存地址以及该对象的值等具体信息, po指令则是打印其 ...
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- Objective C运行时(runtime)
#import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...
- Objective C运行时(runtime)技术的几个要点总结
前言: Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...
- iOS开发——项目实战总结&带你看看Objective-C的精髓
带你看看Objective-C的精髓 1:接口与实现 @interface...@end @implementation...@end @class 接口(头文件) 实现文件 向前引用 注:类别通过增 ...
- Objective C静态代码扫描和代码质量管理 OClint + SonarQube
OClint是针对C, C++及Objective C代码的静态扫描分析工具,而SonarQube是一个开源的代码质量管理平台.本文将实现将OClint的扫描结果导入到SonarQube中,已实现对O ...
- iOS已发布应用中对异常信息捕获和处理
iOS已发布应用中对异常信息捕获和处理 iOS开发中我们会遇到程序抛出异常退出的情况,如果是在调试的过程中,异常的信息是一目了然,但是如果是在已经发布的程序中,获取异常的信息有时候是比较困难的. iO ...
- Objective C运行时(runtime)技术总结,好强大的runtime
前言: Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...
- 。SLI,Service Level Indicator,服务等级指标,其实就是我们选择哪些指标来衡量我们的稳定性。而 SLO,Service Level Objective,服务等级目标,指的就是我们设定的稳定性目标,比如“几个 9”这样的目标。
.SLI,Service Level Indicator,服务等级指标,其实就是我们选择哪些指标来衡量我们的稳定性.而 SLO,Service Level Objective,服务等级目标,指的就是我 ...
- alias导致virtualenv异常的分析和解法
title: alias导致virtualenv异常的分析和解法 toc: true comments: true date: 2016-06-27 23:40:56 tags: [OS X, ZSH ...
随机推荐
- 修改web.config来开启Gzip压缩
IIS 7.0之后引入的一个IIS配置文件,详细内容参考官方链接http://www.iis.net/learn/get-started /planning-your-iis-architecture ...
- centos7+python3.6+nginx+uwsgi+django2的搭建笔记
公司需上线一套python编写的代码,需要给搭建一套环境 ,本次采用centos7+python3.6+nginx+uwsgi2+django2+mysql5.7的方式来进行搭建 写在部署前 在线上 ...
- Music in Car CF 746F
题目:http://codeforces.com/problemset/problem/746/F 先感叹一下题目之长! 一些测试样例在后面给出. 题目大意: Sasha 去工作的路上喜欢听歌,途中经 ...
- JDK源码分析(三)——HashMap 上(基于JDK7)
目录 HashMap概述 内部字段及构造方法 存储元素 扩容 取出元素 删除元素 判断 总结 HashMap概述 前面我们分析了基于数组实现的ArrayList和基于双向链表实现的LinkedLi ...
- [leetcode trie]212. Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- [leetcode sort]56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- Standard NSD file
%pool: pool=system blockSize=256K layoutMap=cluster allowWriteAffinity=no %pool: pool=datapool block ...
- python opencv3 人脸识别的例子
一个人脸识别的例子 程序中用到了公共数据集, 欢迎去我的git上下载源码,源码里带有数据集 git:https://github.com/linyi0604/Computer-Vision 脚本中一个 ...
- fiddler 手机装证书
1: 打开浏览器的地址 输入fiddler 右上方的地址 172.21.14.197:8888 2: 然后点击页面里的 FiddlerRoot certificate 3: 最后验证下 iOS 1 ...
- Go语言特点
作者:asta谢链接:https://www.zhihu.com/question/21409296/answer/18184584来源:知乎 1.Go有什么优势 可直接编译成机器码,不依赖其他库,g ...