14장 점진적인 개선

오류 처리 코드 만들기

public void testInvalidDouble() throws Exception {
	Args args = new Args("x##", new String[] {"-x", "Forty two"});
	assertFalse(args.isValid());
	assertEquals(0, args.cardinality());
	assertFalse(args.has('x'));
	assertEquals(0, args.getInt('x'));
	assertEquals("Argument -x expects a double but was 'Forty two'.",
								args.errorMessage());
}
public class ArgsException extends Exception {
	private char errorArgumentId = "\\0";
	private String errorParameter = "TILT";
	private ErrorCode errorCode = ErrorCode.OK;

	public ArgsException() {}

	public ArgsException(String message) {super(message);}

	public enum ErrorCode {
		OK, MISSING_STRING, MISSING_INTEGER, INVALID_INTEGER,
		UNEXPECTED_ARGUMENT, MISSING_DOUBLE, INVALID_DOUBLE}
}