Say a list list={{1,2},{3,4}}
, list[[1]]
and list[[2]]
works. But list[[3]]
gives an error of
Part::partw: Part 3 of {{1,2},{3,4}} does not exist.
This is alright, since there's no part 3 indeed. But what if I wish to handle that error. So in this case, I want to return empty list {}
if the part-does-not-exist error happens.
I try to refer to https://reference.wolfram.com/language/ref/Catch.html, but it seems to be involved with Throw
. Therefore I try to think of a simpler scenario as above.
Indexed[]
? $\endgroup$ – J. M.'s ennui♦ Mar 21 '20 at 10:29Indexed[list,3]
would also give error. $\endgroup$ – liang Mar 21 '20 at 11:19