Designing exceptions for conversion failures
Posted
by
Mr.C64
on Programmers
See other posts from Programmers
or by Mr.C64
Published on 2012-10-31T11:05:44Z
Indexed on
2012/10/31
11:13 UTC
Read the original article
Hit count: 264
design
|exceptions
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. anenum
) specifying the direction of the conversion (e.g.ConversionFromXToY
,ConversionFromYToX
). - A
XYConversionException
class, with two derived classesConversionFromXToYException
andConversionFromYToXException
. ConversionFromXToYException
andConversionFromYToXException
classes without a common base class.
© Programmers or respective owner