zoukankan      html  css  js  c++  java
  • 断言--NSAssert

    • NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异常描述。NSAssert()是这样定义的:
      • #define NSAssert(condition, desc)
      • condition是条件表达式,值为YES或NO;desc为异常描述,通常为NSString。当conditon为YES时程序继续运行,为NO时,则抛出带有desc描述的异常信息。NSAssert()可以出现在程序的任何一个位置。
    • 示例:
      • NSArray *arr = @[@"1",@"2"];
        NSAssert(arr != nil, @" arr is nil");
        NSLog(@"23456”);  //正常打印 23456
      • int a = 1;
        NSAssert(a != 1, @"a != 1");
        NSLog(@"23456”); //抛出异常a != 1
      • *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'a != 1'
    • NSParameterAssert()NSParameterAssert()只需要一个参数,如果参数存在程序继续执行,如果参数为空,则程序停止打印
      • int a = 1;
        NSParameterAssert(a);
        NSLog(@"23456");
  • 相关阅读:
    springboot中添加自定义filter
    一台电脑同时运行多个tomcat配置方法:
    web 后台数据交互的方式
    xml
    开发互联网应用与开发企业级应用有什么异同
    新学期目标
    换了呗项目总结
    换了呗项目
    黄金点游戏
    自我介绍
  • 原文地址:https://www.cnblogs.com/10-19-92/p/5318412.html
Copyright © 2011-2022 走看看