Hello Everyone,
I need some help with a Method where I want to throw Exceptions on certain Conditions.
If you use the Method and if any of those Conditions to throw a Exception is true, then it should give us an Exception but I don't know how to implement this right.
This is the Code:
public static SoulType register(String id, String displayName, SoulTypeRarities rarity, double corruption, double strength) {
double minCorruption = 0;
double maxCorruption = 2;
double minStrength = 0;
double maxStrength = 5;
if (SOUL_TYPES.containsKey(id)) {
throw new IllegalArgumentException("SoulType with id '" + id + "' already exists.");
}
if (corruption < minCorruption || corruption > maxCorruption) {
throw new IllegalArgumentException("Corruption must be between " + minCorruption + " and " + maxCorruption + " .");
}
if (strength < minStrength || strength > maxStrength) {
throw new IllegalArgumentException("Strength must be between " + minStrength + " and " + maxStrength + " .");
}
SoulType newType = new SoulType(id, displayName, rarity, corruption, strength);
SOUL_TYPES.put(id, newType);
return newType;
}