使用NSAssert进行代码调试
2014-12-11 01:07
218 查看
开发ios程序时调试的好帮手---NSAssert()函数
代码如下: NSAssert(x!=0,@"x must not be zero");
在表达式“x!=0”不成立时,程序就会抛出异常,并显示自定义的消息"x must not be zero",并同时显示出错的文件、代码和调用函数等信息,是一个程序追踪的很好手段。
假设x!=0,不满足要求就提示reason-x must not be zero
assert 是C里面的宏。用于断言。
NSAssert 只能在Objective-c里面使用。是assert的一个扩充。能捕获assert类异常及打印一些
可读的日志。而assert只是让app crash(abort).
参考 : http://stackoverflow.com/questions/6616347/nsassert-vs-assert-which-do-you-use-and-when
The basic difference between an NSAssert and a regular assert is that an NSAssertraises an exception when it fails while an assert just crashes the app. NSAssert also lets you supply fancier error messages and logs them. Practically, I really don't think there's
much difference between the two--I can't think of a reason to handle an exception thrown by an assertion. (To split hairs, I think NSAssert usually involves less typing because you don't have to includeassert.h, but that's neither here nor there.)
http://www.wahenzan.com
代码如下: NSAssert(x!=0,@"x must not be zero");
在表达式“x!=0”不成立时,程序就会抛出异常,并显示自定义的消息"x must not be zero",并同时显示出错的文件、代码和调用函数等信息,是一个程序追踪的很好手段。
假设x!=0,不满足要求就提示reason-x must not be zero
assert 是C里面的宏。用于断言。
NSAssert 只能在Objective-c里面使用。是assert的一个扩充。能捕获assert类异常及打印一些
可读的日志。而assert只是让app crash(abort).
参考 : http://stackoverflow.com/questions/6616347/nsassert-vs-assert-which-do-you-use-and-when
The basic difference between an NSAssert and a regular assert is that an NSAssertraises an exception when it fails while an assert just crashes the app. NSAssert also lets you supply fancier error messages and logs them. Practically, I really don't think there's
much difference between the two--I can't think of a reason to handle an exception thrown by an assertion. (To split hairs, I think NSAssert usually involves less typing because you don't have to includeassert.h, but that's neither here nor there.)
http://www.wahenzan.com
相关文章推荐
- 如何使用火狐Firefox的Zend Firefox Toolbar插件和Zend Studio进行代码调试
- 使用UnityVS1.8.2搭配VS2013进行Unity3D代码调试(下载+安装+使用+问题解决)
- docker环境下使用phpstorm进行xdebug调试代码。
- 如何使用Eclipse和GDB对JNI代码进行调试(JAVA和C)
- 说说如何使用 JavaScript 进行代码调试
- 如何在eclipse里面进行PHP代码的调试(使用集成开发环境xampp)
- Python 代码调试技巧使用 PyDev 进行调试
- 我是怎样使用javassist将代码注入到帝国OL并进行调试的
- 使用phpStorm编辑器进行PHP代码的xdebug调试
- .NET Core快速入门教程 5、使用VS Code进行C#代码调试的技巧
- Python 代码调试技巧使用 PyDev 进行调试
- 使用C/C++预定义宏进行调试跟踪代码
- 使用Eclipse(以及intellij IDEA)配合JDWP对服务器上部署的代码进行调试
- 使用Delve进行Golang代码的调试
- [置顶] Linux 使用gdb对c/c++代码进行调试
- 使用Zend Studio和Zend Debugger进行php代码的远程调试
- 使用IDEA进行Lua代码调试、自动提示、代码跳转、智能重命名
- Xcode常用技巧(1)-使用Xcode进行代码分析及GDB调试
- android studio 使用mates真机进行调试,在logcat中无法打印出代码中有Log.d输出的log
- 使用NSight进行CUDA调试,只能进行GPU代码调试,不能进入CPU端代码断点