Catching an exception class by value rather than by reference can cause several problems:
- Memory is allocated unnecessarily: catching by value creates a copy of the exception object, which is destroyed at the exit of the catch block.
- Slicing occurs: the copy will be an instance of the exception base class rather than the potentially more specific exception class initially
caught. So it may lead to a loss of precision as any additional data or functionality offered by the subclass will not be accessible.
- Copying the exception class may throw an exception, leading to unexpected behavior.