Best practices for defining your own exception classes?

前端 未结 5 800
走了就别回头了
走了就别回头了 2020-12-28 12:57

I have some special exception cases that I want to throw and catch, so I want to define my own exception classes.

What are the best practices for that? Should I inh

5条回答
  •  抹茶落季
    2020-12-28 13:39

    It is a good when exception is placed in some scope. For instance class Manipulation can declare inside exception classes Error.

    and catch them like

    catch ( const Manipulation::InputError& error )
    catch ( const Manipulation::CalculationError& error )
    

    In such cases they can be just empty classes without any additional error information unless you design allows those exceptions fly much upper where you catch all standard exceptions.

提交回复
热议问题