On Dec 19, 8:56 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Manuel wrote:
Hello.
I have a class where the object are created with the data retrieved
from a db.
The data retrieved is an image and when this data doesn't exist the
constructor must generate it.
well, i have doubts to do this.
I think that i have two ways for this. The first is create an
exception that it is throw when the data are not and in the "catch
sentence" the data would be generated and the second is using an "if
sentence"
what way is better? how is more elegant?If you dig around for "exception vs error code", you'll probably see
more than one opinion. I think that exceptions are not good for what
you need here. Improper data happen all the time, and it should be
treated as a normal situation and not an exceptional one. If you have
to design a mechanism to respond to incorrectly formatted or simply
wrong data, it's another sign that exceptions are not for that. In
an exceptional situation you usually just log what happened and bail
out. It is more likely that you cannot work around an exception. If
you can think of a work-around, you should probably employ error code
mechanism (the "if sentence").
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Well, My doubt is not around for "exception vs error code", i think.
the question isn't that it retrieved improper data.
The question is that it can or can not be the image data in the db. In
case it isn't data, the constructor must generate it.
after i read your mail and the Salf_peter's mail I think that i must
add other way: Make two constructors, one that has the parameter data
and other that hasn't it and it must connect to db to read de image
data.
This method implies that in the class where it is made an instance of
the primary class must connect it to db too. i don't know if it is
correct because the data access object is used in more places
i don't decide that is the better choice but I incline by the last
option
Best regards
M.