类层次结构中的C ++异常处理
问题描述:
在异常类层次结构中,catch语句的正确排序是什么,以便允许异常类的层次结构中的多个类的异常被捕获?
In a hierarchy of exception classes, What is the correct ordering of catch statements so as to allow exceptions of more than one class from the hierarchy of exception classes to be caught?
最多是派生到基础还是最基础的派生?
Is it most derived to the base or the base to most derived?
答
处理程序按出现的顺序进行匹配,因此您最想使用最具体的字符。
Most derived first. Handlers are matched in the order they appear, so you want the most specific ones first.