Verify the Exception Message

What should we do if our exception handling is not as simple and clean as in Listing 11-1? Perhaps we want to include a message with the exception that depends on the exact RemoteException thrown. Maybe we are writing an object-oriented wrapper around a procedural API and want to throw a different exception or include a different message depending on the error value. Listing 11-4 gives a simple example of the former scenario.

Listing 11-4: Exception handling with multiple isomorphic exception paths. An alternative implementation would create an exception hierarchy from ServiceFailureException to distinguish the cases using techniques from the previous section.

public class SomeClass ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.