Adrian Crum wrote: > --- On Fri, 2/12/10, Adam Heath <[email protected]> wrote: >> It's also why I throw UnsupportedOperationException, >> instead of >> ConversionException, during convert(obj). You >> shouldn't do doing >> unknown conversions, when dealing with enums. In >> those cases, you >> should know that an enum is being requested, and use the >> other convert >> method. > > But the client code is checking for ConversionException, and typically takes > an alternate path when one is thrown. Throwing UnsupportedOperationException > breaks that pattern.
ConversionException means that there was a problem converting. Calling convert(Object) on StringToEnum is not a valid call to make, it's a more serious issue. It's not that a conversion failed, it's that a conversion is not even allowed to take place. You *must* use the convert(Class, Object) variant. StringToEnum can handle all enums, but can only create concrete sub-classes. It's not like List or Map, which allows any implementation to be used.
