zoukankan      html  css  js  c++  java
  • iOS

    1、@try 语句

    	@try {
        
        	// Code that can potentially throw an exception  可能会抛出异常的代码块
        
        	statement
        	. . .
        
    	} @catch (NSException *exception) {
        
        	// Handle an exception thrown in the @try block  处理 @try 块抛出的异常
        
        	NSLog(@"%@, %@", [exception name], [exception reason]);
        
        	statement
        	. . .
        
     	} @finally {
        
        	// Code that gets executed whether or not an exception is thrown  无论是否抛出异常都要被执行的代码块
        
        	statement
        	. . .	
    	}
    
    • 当出现异常时,@catch 块被执行。包涵异常信息的 NSException 对象作为参数传递给这个块。name 监测异常的名称,reason 方法给出原因(运行时系统还是会将原因自动输出)。

    • 在 @catch 块中的最后一条语句执行后,程序会立即执行之后的语句,程序并不会终止运行。

    • 在 iOS 开发时很少使用 try catch 错误处理机制,因为 iOS ARC 开发时,所有 retain, release, autorelease 都是编译自动增加的,一旦使用了 try catch,程序如果出现异常,系统没有办法准确的判断第几个语句出现问题,导致 retain, release 失衡,会造成内存泄漏。

  • 相关阅读:
    react axios 跨域访问一个或多个域名
    基础复习1
    Webpack笔记
    小程序笔记下
    小程序笔记上
    webpack-dev-server的使用
    webpack资源加载常用配置
    vue实现组件切换的两种方式
    vue实现一个评论列表
    子组件调用父组件的数据及方法
  • 原文地址:https://www.cnblogs.com/QianChia/p/5780694.html
Copyright © 2011-2022 走看看