Can you catch an exception by the type of a conversion operator?

前端 未结 1 850
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 06:31

I don\'t know how to phrase the question very well in a short subject line, so let me try a longer explanation. Suppose I have these exception classes:

clas         


        
相关标签:
1条回答
  • 2020-12-06 06:58

    You cannot. Standardese at 15.3/3:

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

    • 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

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

    0 讨论(0)
提交回复
热议问题