The standard practice for exceptions in C++ is ...
Throw by value, catch by reference
Catching by value is problematic in the face of inheritance hierarchies. Suppose for your example that there is another type MyException
which inherits from CustomException
and overrides items like an error code. If a MyException
type was thrown your catch block would cause it to be converted to a CustomException
instance which would cause the error code to change.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…