且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

您可以通过转换运算符的类型捕获异常吗?

更新时间:2023-11-11 13:32:58

你不能。标准在 15.3 / 3


处理程序是一个异常对象的匹配如果

A handler is a match for an exception object of type E if


  • 处理程序的类型为$ code> cv T 或 cv T& 和E和T是相同的类型(忽略***cv-
    限定词),或者

  • 处理程序是 cv T cv T& ,T是E的明确的公共基类,或

  • 处理程序的类型为 cv1 T * cv2 ,E是可以转换为处理程序类型的指针类型
    通过


    • 不涉及到私有或受保护的指针的转换的标准指针转换(4.10)或
      模糊类

    • 资格转换

    • The handler is of type cv T or cv T& and E and T are the same type (ignoring the top-level cv- qualifiers), or
    • the handler is of type cv T or cv T& and T is an unambiguous public base class of E, or
    • the handler is of type cv1 T* cv2 and E is a pointer type that can be converted to the type of the handler by either or both of
      • a standard pointer conversion (4.10) not involving conversions to pointers to private or protected or ambiguous classes
      • a qualification conversion

      您所需的场景不符合这些情况。 cv 表示const和/或volatile组合

      Your desired scenario matches none of these. cv means "const and/or volatile combination"