Module talk:Mapshapes

From Wikivoyage
Jump to navigation Jump to search

Code snippet to trap error[edit]

The following is a snippet of some function code to catch an error:


if pcall(function () t = entity.claims.P150[count].mainsnak.datavalue.value end) then

t = entity.claims.P150[count].mainsnak.datavalue.value
return t
else
return "ERROR"

end


hope this is helpful -- Matroc (talk) 07:27, 12 December 2018 (UTC)[reply]
Hmmm, that would make the code a bit nasty, if I had to check every call like this :-( But perhaps at least it can be done around the call to showOne(). I'll put it on my TODO list, thanks! -- andree.sk(talk) 11:07, 15 December 2018 (UTC)[reply]
I have only used this type of thing on rare occasions where I hit an issue with a particular Wikidata problem rather than cycle through and checking for "nil" or "" for every piece. Yes use sparingly, it costs as you are checking code to see if it works and if no errors running the code again to get the result. Sorry I can't explain it very well. -- Matroc (talk) 05:50, 17 December 2018 (UTC)[reply]