Why won’t this code throw an exception? Have tried a lot of things but when I test it with a JUnit class like this, for example, it won’t throw an exception:
Vehicle e = new Vehicle('C', 'G', "A1234");
// Constructor
public Vehicle(char kType, char dType, String regNr) {
String temp0 = regNr.substring(0, 2);
String temp = regNr.substring(2);
boolean finish = false;
if ("" + kType == "C") {
for (char c : temp0.toCharArray()) {
if (Character.isDigit(c)) {
throw new IllegalArgumentException("3");
}
}
if (temp.length() == 5) {
finish = true;
} else {
finish = false;
throw new IllegalArgumentException("4");
}
try {
Integer.parseInt(temp);
} catch (NumberFormatException nfe) {
finish = false;
throw new IllegalArgumentException("5");
}
}
}