Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Handling KeyError: key “nameOfKey” not found

$
0
0

I have a script that looks through a JSON structure. Every now and again, a particular key is missing. When these instances occur, I need the script to continue rather than stop. Here is my code:

for i = 1:length(marketCatalogueResult)
        marketResults = getMarketOffers(currentCatalogue[i,1])
        push!(lastTradeP1, marketResults[1]["runners"][1]["lastPriceTraded"])
        push!(lastTradeP2, marketResults[1]["runners"][2]["lastPriceTraded"])
    end
end

The error I sometimes get is:

KeyError: key "lastPriceTraded" not found

How can I amend my code to handle the stated error?

9 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles