异常:NSException和NSAssert的简单使用
//断言
- (void)NSAssert_Test:(NSString *)string{
NSAssert(string == nil, @"string == kong or nil");
}
-----------------------------------------------------------------
//异常
- (void)NSException_Test{
_num++;
NSException *excep = [[NSException alloc] initWithName:@"BENG" reason:@"dian l 3 xia!" userInfo:@{@"reason": @"3 times clicked!"}];
@try {
switch (_num) {
case :{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:excep.name message:excep.reason delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:].text = excep.userInfo[@"reason"];
[alert textFieldAtIndex:].placeholder = @"enter:123";
[alert textFieldAtIndex:].delegate = self;
[alert show];
_alert = alert;
@throw excep;//num==3抛出异常
}break;
default:
break;
}
NSLog(@"try:%d",_num);
}
@catch (NSException *exception) {//捕获异常
_num = ;
NSLog(@"catch:%@--%@",exception,exception.userInfo);
}
@finally {
NSLog(@"finally:");
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *all = [textField.text stringByReplacingCharactersInRange:range withString:string];
if ([all isEqualToString:@""]) {
[_alert dismissWithClickedButtonIndex: animated:YES];
}
return YES;
}
链接:
iOS被开发者遗忘在角落的NSException-其实它很强大
异常:NSException和NSAssert的简单使用的更多相关文章
- iOS 利用异常 NSException 调试代码
可以用在代码的调试上: -(instancetype)init{ @throw [NSException exceptionWithName:@"Singleton" reason ...
- 系统异常 NSException.h
FOUNDATION_EXPORT NSExceptionName const NSGenericException; FOUNDATION_EXPORT NSExceptionName const ...
- 使用NSAssert()和NSParameterAssert调试程序
NSAssert: NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异 ...
- iOS 10开发NSAssert(断言)的使用
断言(NSAssert)的使用 字数1055 阅读3270 评论3 喜欢30 NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug ...
- 【转】使用断言NSAssert()调试程序错误
NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...
- 使用断言NSAssert()调试程序错误
NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...
- JAVA 线程中的异常捕获
在java多线程程序中,所有线程都不允许抛出未捕获的checked exception(比如sleep时的InterruptedException),也就是说各个线程需要自己把自己的checked e ...
- 【javascript进阶】异常
前言 最近有些时间了,今天看了看博客的后台记录,好多都没有写博客呢,争取尽快把以前的补上,javascrit中的异常在前端大家用的好像不是很多,其实javascript的异常和大多数的后端语言差不大, ...
- C语言异常与断言接口与实现
程序中通常会出现三种错误:用户错误.运行期错误以及异常 欢迎关注我的个人博客:www.wuyudong.com, 更多精彩文章与您分享 标准库函数setjmp和longjmp 在C语言中,标准库函数s ...
随机推荐
- 实验12:Problem I: 成绩排序
Home Web Board ProblemSet Standing Status Statistics Problem I: 成绩排序 Problem I: 成绩排序 Time Limit: 1 ...
- 3.0之后在LinearLayout里增加分割线
android:divider="@drawable/shape"<!--分割线图片--> android:showDividers="middle|begi ...
- 流媒体一些server
(1)darwin stream server (2)red5 (3)nginx rtmp
- 【读书笔记】iOS-装箱
通常将一个基本类型的数据包装成对象叫做装箱,从对象中提取基本类型的数据叫做取消装箱.有些语言有自动装箱功能,它可以自动包装基本基础类型的数据,也可以自动从包装后的对象中提取基础数据.Objective ...
- iOS实现(超级猜图)源码
//首先建立模型文件 QLLQuestion.hheQLLQuestion.m文件 #import <Foundation/Foundation.h> @interface QLLQues ...
- IOS之UI--小实例项目--添加商品和商品名
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Xcode模板修改
本小节知识点: 修改项目模板 修改类的头部信息 1.修改项目模板 项目模板就是创建工程的时候选择的某一个条目, Xcode会根据选择的条目生成固定格式的项目 例如想创建一个命令行项目就选择Comman ...
- System.Data.Entity 无法引用的问题
最近刚学MVC,跟着网上的博客学习,发现代码中有这样一句: using System.Data; using System.Data.Entity; 我项目引用的时候,也引用了System.Data. ...
- ADO.NET Entity Framework,Code First简单示例
一.安装EntityFramework: 在vs里打开NuGet,在命令行里输入:Install-Package EntityFramework. 二.基本使用方法 1.建立数据模型 class St ...
- SQL Server 2008 R2——VC++ ADO 操作 存储过程
==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...