I have a class constructor that needs to perform a couple checks. It is checking a file for the occurrence of a few tags. I use a function that checks for the tags and returns a boolean value depending on whether the tag was found. If the tag was not found it calls
return, stops executing the constructor and sets the
alive flag to
false. I cannot throw an exception in this case.
At the moment the code looks like this:
if (!tagExists(tag1)) print(tag1 + " failed") alive = false return if (!tagExists(tag2)) print(tag1 + " failed") alive = false return
And this continues for the amount of tags there is. What would be the best way to refactor this? As I said, I cannot use exceptions.