ITEM 75: INCLUDE FAILURE-CAPTURE INFORMATION IN DETAIL MESSAGES
307
One way to ensure that exceptions contain adequate failure-capture
information in their detail messages is to require this information in their
constructors instead of a string detail message. The detail message can then be
generated automatically to include the information. For example, instead of a
String
constructor,
IndexOutOfBoundsException
could have had a constructor
that looks like this:
/**
* Constructs an IndexOutOfBoundsException.
*
* @param lowerBound the lowest legal index value
* @param upperBound the highest legal index value plus one
* @param index the actual index value
*/
public IndexOutOfBoundsException(int lowerBound, int upperBound,
int index) {
Do'stlaringiz bilan baham: