A Java boss asked me if I would try to catch me saying I wouldn't learn this long or listen to friends around with this because the Apple console could have printed the exception
I hereby examine it.
1.try catch: Is the catch Exception code snippet feature: real-time monitoring of code takes up a lot of resources
2. Try and catch are seldom used in iOS
in simple terms, Apple has provided both error handling (NSERROR) and exception handling (exception) mechanisms, but Apple has encouraged developers to use Nserror to handle recoverable errors in program operations. Exceptions are recommended to handle unrecoverable errors. There are several reasons why, in non-GC cases, exception is prone to memory management problems (it is not safe to describe the document even under ARC); exception uses blocks to create extra overhead, less efficiency, and so on, and this is really cocoa developer's habit. (http:///blog.csdn.net/x32sky/article/details/23753597)// No wonder I didn't listen around iOS developers using this
3.try,catch,finally Execution Process (http://blog.csdn.net/phoenix001/article/details/4293472)
Try{//1: The code that throws the exception//2: Code}Catch(){//3: Code//4: Throw exception}finally{//5: Code}//6: Codethe first point to make clear is that the finally statement block executes regardless of whether the try throws an exception. Careful attention, 6!!. The whole try,Catch, finally, the following scenarios are performed:1: The TRY statement block does not throw an exception. If this is the case, the program executes the code after the try,finally and finally blocks;2: The Try statement block throws an exception and the catch has a matching exception. After encountering the exception thrown in the try block, the remaining code inside the try blocks is not executed and jumps to the catch block. This can be divided into 2 different situations. First, the thrown exception is caught by the catch, and the catch does not throw a new exception, then the execution order is 1356, and the second, if the catch inside throws a new exception, the order is 1345, and then returns the new exception to the method caller, 6 does not execute;3: The Try statement block throws an exception, but the following catch does not have an exception to match. Then the statement inside the try and finally is executed, which is 15, and the exception is returned to the method caller without executing 6. Summary: If the exception cannot be captured,finallyThe statement after {} will not be executed, and finally{} must be executed
4. For example, use
@try { } @catch(nsexception *exception) { NSLog (@ "exception:%@ ", exception); } @finally { }
iOS development-Exception handling-uses try and catch to catch errors.