rspec/rules/S3696/description.adoc

8 lines
805 B
Plaintext
Raw Normal View History

2020-12-23 14:59:06 +01:00
Just because you _can_ stick your hand in a blender, that doesn't mean you _should_. Similarly, you _can_ ``throw`` anything, but that doesn't mean you _should_ ``throw`` something that's not derived at some level from ``std::exception``.
2020-06-30 12:48:39 +02:00
2020-12-23 14:59:06 +01:00
If you can't find an existing exception type that suitably conveys what you need to convey, then you should extend ``std::exception`` to create one.
2020-06-30 12:48:39 +02:00
2020-12-23 14:59:06 +01:00
Specifically, part of the point of throwing exceptions is to communicate about the conditions of the error, but primitives have far less ability to communicate meaningfully than ``exception``s. And, the creation of some other object type could itself ``throw`` an exception, resulting in program termination.
2020-06-30 12:48:39 +02:00
2020-12-23 14:59:06 +01:00
Further, ``catch``ing non-exception types is painful and fraught with the potential for (further) error.