Verify the Exception Instance

Each of the exception-based techniques so far essentially tried to infer the identity of the exception that we think should have been thrown by inspecting its characteristics: type, message, cause, and extended attributes. We have used increasing levels of detail to increase our confidence that we have identified the exception properly. You may have asked yourself, “Why not just inject the exception itself? Why not just use identity to verify identity?” That is the question this section addresses.

It almost goes without saying that identity is the strongest way to verify identity. But with objects—and particularly with exceptions—mutability and context are important.

Mutability refers to an object’s ability to be ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.