Designing exceptions for conversion failures
- by Mr.C64
Suppose there are some methods to convert from "X" to "Y" and vice versa; the conversion may fail in some cases, and exceptions are used to signal conversion errors in those cases.
Which would be the best option for defining exception classes in this context?
A single XYConversionException class, with an attribute (e.g. an
enum) specifying the direction of the conversion (e.g.
ConversionFromXToY, ConversionFromYToX).
A XYConversionException class, with two derived classes
ConversionFromXToYException and ConversionFromYToXException.
ConversionFromXToYException and ConversionFromYToXException classes
without a common base class.