Hi,
I am writing an application in which I make
a map of strategies keyed by a string symbol. In
order to construct the strategies I pass the constructor
a filename, out of which it reads out some data, into an initializing map.
It is possible that some data might be missing from the initializing map,
in which case I simply want to skip this strategy. I am
thinking that, to implement this I need to throw an exception
if the data is missing. But I am unsure how to implement this, as
I have never used exceptions before. Inside the constructor, my proposed
code looks like:
if( calMap_.find(string("MuSCurve"))==calMap_.end()) {
delete _estimatorIntegrator;
throw MissingData();
}
The calling code looks like:
while (!symbolStream.eof()) {
symbolStream >> symbol;
std::string calPathBase(calFileDirectory_ + symbol);
try{ TradingStrategy* ts( new TradingStrategy(calPathBase,symbol)); }
catch ( MissingData() ) { continue;}
_strategies[symbol] = ts;
}
Do I have to delete any new-ed pointers in the constructor before
throwing? Do I need to delete the ts pointer in the calling code,
if the exception is thrown?