zoukankan      html  css  js  c++  java
  • iOS 利用异常 NSException 调试代码

    可以用在代码的调试上:

    -(instancetype)init{

        

        @throw [NSException exceptionWithName:@"Singleton" reason:@"Use [GloabData shareData]" userInfo:nil];

        

        return  nil;

    }

    或者:

     NSException * e = [[NSException alloc] initWithName:@"Singleton" reason:@"Use [GloabData shareData]" userInfo:nil];

        @throw e;

     

    抛出了一个bug:

    关于异常的处理:

            NSException* ex = [[NSException alloc] initWithName:@"ExceptionName"   // just for test                                        
         reason:@"XXX"
             userInfo:nil];
         CustomNSException* ex = [[CustomNSException alloc] initWithName:@"CustomNSExceptionName" // just for test reason:@"XXX" userInfo:nil];

    @try { bool error = YES;  

             if (error) {  

             @throw ex;  

                   }  

    }

        @catch ( CustomNSException *exception ) {     
            NSLog(@"CustomNSException.name = %@" ,CustomNSException.name);
           NSLog(@"CustomNSException.reason = %@" , CustomNSException.reason);

    UIAlertView* alert = [[UIAlertView alloc]   initWithTitle:CustomNSException.name  message:CustomNSException.reason                                         delegate:nil  cancelButtonTitle:nil   otherButtonTitles:nil];  

          [alert show]; 

    }  

    @catch ( NSException *exception ) {  

         NSLog(@"exception.name = %@" , exception.name);      

        NSLog(@"exception.reason = %@" , exception.reason);  

    }  

    @finally {  

            NSLog(@"@finally");  

      }

  • 相关阅读:
    通讯技术
    (1)sqlserver2017安装
    c# api身份验证和授权
    ()centos7 安装python36
    python 包管理
    ()centos7 安装mysql8.0
    [bzoj1095][ZJOI2007]Hide 捉迷藏 点分树,动态点分治
    bzoj 3544 [ONTAK2010]Creative Accounting 贪心
    BZOJ4300 绝世好题 dp
    bzoj 4295 [PA2015]Hazard 贪心,暴力
  • 原文地址:https://www.cnblogs.com/feiyafeiblog/p/5041537.html
Copyright © 2011-2022 走看看