MATLAB: Does the Bloomberg FETCH command error out when fetching historical data for certain fields in Datafeed Toolbox 2.1 (R2007b)

Datafeed Toolbox

I am using the FETCH command in a loop. I encounter problems because some of the fields for which historical requests are made are unsupported. For instance, using the 'INDX_MEMBERS' field with FETCH:
fetch(connect,'S5FINL Index','History','INDX_MEMBERS')
returns the error:
??? Error using ==> bloomberg.fetch at 450
No historical data was returned. Field list may contain entry that is invalid for historical data requests.
I am well aware of this, but I would like to make the FETCH function not return an error but a NaN when it comes across a bad field. This way my program can continue to loop even if the fields are not available.

Best Answer

This ability is not available in Datafeed Toolbox 2.1 (R2007b).
To work around this issue, you should put the calls in a loop within a TRY/CATCH block. This way, if an error occurs during execution of any of the statements, the error is captured, while the statements between the catch and end are executed. The syntax for a try/catch loop might look something like the following
for index = 1:10
try
results = fetch(connect,'S5FINL Index','History','INDX_MEMBERS');
catch
results = NaN;
end
end
The MATLAB documentation describes how to use TRY/CATCH blocks. There is also a section in Tech Note 1207 on our support website that describes the TRY/CATCH block.