异常机制的本质-异常机制是一种信息传递机制

异常机制的本质:

 用冗余代码实现额外信息的传递:

异常机制的本质是异常机制代码的解释权:

作出解释即用冗余代码实现异常机制的额外逻辑;

1、异常信息的表达:包含什么:在哪里出的什么错误;

2、异常信息的传递:栈帧、长跳转;

3、异常的处理:

                /**

                 * 抛出异常对象,对应代码:@throw e;

                 * 

                 * objc_exception_throw函数实现步骤如下:

                 * 1. 把e对象保存到_stack->pointers[0]中使其在@catch{}中能被捕获。

                 * 2. 将_stack从全局栈中弹出。

                 * 3. 调用_longjmp()跳转到前面if语句中的_setjmp()位置。_longjmp()使得_setjmp()函数第二次返回,

                 * 返回值为1,所以会执行else{}中也就是@catch{}中的代码。

                 */

                objc_exception_throw(e);

https://www.cnblogs.com/feng9exe/p/7241609.html

In general, an exception breaks the normal flow of execution and executes a pre-registered exception handler. The details of how this is done depends on whether it is a hardware or software exception and how the software exception is implemented. Some exceptions, especially hardware ones, may be handled so gracefully that execution can resume where it was interrupted.

https://www.cnblogs.com/feng9exe/p/7241575.html

现代程序的规模已经大到让人无法全知的程度,因此异常机制是一种很有效的机制。

异常信息的返回与处理

原文地址:https://www.cnblogs.com/feng9exe/p/10595108.html