Whether or not an exception is warranted is completely dependent on
your specification for this class. If the SKU is defined in such a way
that under no circumstances may it ever contain a null value, then the
exception is just about demanded.
The only alternative -- based on the very limited view of your code 8-)
-- is to supply a setter and defer the exception to that point. So it
may be created with a null value as long as a good value is passed in
before it is used.
However, doing it that way makes the class code more complicated and
also makes your application code more complicated. You have to verify
that a good value was stored in it before each use or catch a possible
exception at each use. As the creation of objects tends to be limited
to certain areas and the use of the objects tend to be scattered around,
in general it makes more sense to detect invalid conditions as much as
possible during the construction of the objects.
We all know that it is always best to find a bug/error in our code as
soon as we can. Finding and fixing a bug becomes much more difficult
and expensive the further along the development process the bug is
discovered. The same with errors in a running program. If the user
enters erroneous data, or there are any other conditions that are
creating erroneous data, it is best to discover this and alert the user
as soon as possible.
I emphasize the phrase "in general" but I would have to vote for
constructors throwing as many exceptions as it is feasible for them to
throw.
Tomm
Repine, Burt wrote:
>>> Doing it leads to laborious try catch blocks in all the client code
> using the API.
> I totally agree - it seems the only benefit of this is to try and
> catch errors during development/compile time and is extra processing
> and not useful in production.
>
> Here is a snippet of one of the constructors of the classes - remember
> these follow the Value Object pattern so they're really data
> containers with no real brains built in 'em:
>
> public class PackageSkuValueObject extends SkuValueObject implements
> Serializable
> {
> private String pkgSkuId;
>
> public void PackageSkuValueObject(String skuId) throws
> InventoryAppException
> {
> if (skuId == null)
> throw new InventoryAppException(1009010);
>
> pkgSkuId = skuId;
> }
> }
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________