Structured Exception Handling

本文介绍结构化异常处理相关内容,包括异常过滤器与处理程序的区别,try 块使用规则。还提及全局展开、停止全局展开、EXCEPTION_CONTINUE_EXECUTION 情况、异常栈、软件异常、异常链、未处理异常处理,以及首次和最后机会通知等内容。
0. General
Take care of the difference between Exception Filter and Exception Handler.
A try block can't have both a finally block and an except block, and a try block can't have multiple finally or except blocks.
Although return, goto, continue, and break statements are strongly discouraged in the try block of a termination handler, no speed or code-size penalty is associated with using these statements inside the try block of an exception handler. Such a statement in the try block associated with an except block won't incur the overhead of a local unwind. 

Unlike termination handlers, exception filters and exception handlers are executed directly by the operating system—the compiler has little to do with evaluating exception filters or executing exception handlers.

1. Global Unwind: When an exception filter evaluates to EXCEPTION_EXECUTE_HANDLER, the system must perform a global unwind. The global unwind causes all of the outstanding try-finally blocks that started executing below the try-except block that handles the exception to resume execution.

2. Halting Global Unwind: We may halting the Global Unwind through putting a return statement inside a finally block. Note: this will cause all the following(which after the return statement) finally block and the exception handler to be skipped.

3. EXCEPTION_CONTINUE_EXECUTION: When the system sees that the filter evaluated to EXCEPTION_CONTINUE_EXECUTION, it jumps back to the instruction that generated the exception and tries to execute it again. Note: this may be problem, since the invalid address is pre-loaded in the original instructions, not the current instruction.

4. Exception Stack: When an exception occurs, the operating system pushes the following three structures on the stack of the thread that raised the exception: the EXCEPTION_RECORD structure, the CONTEXT structure, and the EXCEPTION_POINTERS structure.
The most important thing to remember about the GetExceptionInformation function is that it can be called only in an exception filter—because the CONTEXT, EXCEPTION_RECORD, and EXCEPTION_POINTERS data structures are valid only during the exception filter processing. Once control has been transferred to the exception handler, the data on the stack is destroyed.

5. Software Exception: Microsoft has done some trickery for EXCEPTION_CONTINUE_EXECUTION so that execution continues after the call to the RaiseException function.(Not re-execute the RaiseException )

6. Exception Chains:  if during the processing of one exception another exception is raised, the first EXCEPTION_RECORD structure contains information about the most recently raised exception and the ExceptionRecord member of this first EXCEPTION_RECORD structure points to the EXCEPTION_RECORD structure for the previously raised exception.

7. Unhandled Exception: We may turn of Unhandled Exception dialog through SetErrorMode(SEM_ NOGPFAULTERRORBOX)

When a debugger is attached to the application, if all the exception filters in debuggee return EXCEPTION_CONTINUE_SEARCH, the system knows to contact the debugger and tell the debugger that the debuggee has just had an unhandled exception.(So windows' default Unhandled Exception dialog just invoke a debugger and return EXCEPTION_CONTINUE_SEARCH for debbuger to process)

8. First-chance notification and Last-chance notification
First-chance notification:
The notification before the Exception Filter is executed.
Last-chance notification: If all of the exception filters return EXCEPTION_CONTINUE_SEARCH, the operating system notifies the debugger again with a last-chance notification

转载于:https://www.cnblogs.com/jeffreytan/archive/2005/03/06/113954.html

【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)》的技术资源,聚焦于电力系统中低碳经济调度问题,结合N-1安全准则与分布鲁棒机会约束(DRCC)方法,提升调度模型在不确定性环境下的鲁棒性和可行性。该资源提供了完整的Matlab代码实现,涵盖建模、优化求解及仿真分析全过程,适用于复杂电力系统调度场景的科研复现与算法验证。文中还列举了大量相关领域的研究主题与代码资源,涉及智能优化算法、机器学习、电力系统管理、路径规划等多个方向,展示了广泛的科研应用支持能力。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事能源调度、智能电网相关工作的工程师。; 使用场景及目标:①复现高水平期刊(如EI/SCI)关于低碳经济调度的研究成果;②深入理解N-1安全约束与分布鲁棒优化在电力调度中的建模方法;③开展含新能源接入的电力系统不确定性优化研究;④为科研项目、论文撰写或工程应用提供可运行的算法原型和技术支撑。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码与案例数据,按照目录顺序逐步学习,并重点理解DRCC建模思想与Matlab/YALMIP/CPLEX等工具的集成使用方式,同时可参考文中列出的同类研究方向拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值