public class InvalidEnumValueException extends RuntimeException
Exception-class for int-to-enum conversions, when the given int-value exceeds the valid values of the enum.
Example:
enum ExampleEnum { ONE, TWO, THREE, FOUR; // cache all the values defined above in static array for fast int-to-enum conversion private static final JavaType[] VALUES = values(); / ** * This method takes an arbitrary int value and returns the appropriate enum-value In case the * int-value is not a valid value of the enum, an Exception will be thrown. * * @param value * The integer value to convert into the enum (also called "ordinal") * * @return the enum-object associated with the given ordinal. * * @throws de.dimensionv.java.libraries.common.exceptions.InvalidEnumValueException * if value is not a valid value for the enum. * / public static JavaType fromOrdinal(int value) { try { return VALUES[value]; } catch(ArrayIndexOutOfBoundsException ex) { throw new InvalidEnumValueException(value, VALUES.length-1); } } }
Constructor and Description |
---|
InvalidEnumValueException(int value,
int maximum) |
Modifier and Type | Method and Description |
---|---|
int |
getMaximum() |
int |
getValue() |
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Copyright © 2014. All Rights Reserved.