I have been looking at some of the questions regarding error handling but i think my problem is unique.
I am running a Do-loop. I get errors only for certain values of the loop variable due to the nature of the problem.
Example
a = {1, 2, 3, 4, 5};
b = {2, 0, 40, 5, 0};
x = {};
Do[Append[x, a[[i]]/b[[i]]], {i, 1, 5}]
At iterations 2 and 5 the above code gives the error message
Power::infy: Infinite expression 1/0 encountered. >>
I want to know at which index value an error occurs -- any error, not only the particular error given it the example -- and I want to store those values in a variable. I have looked at documentations for Check
, Catch
, etc., but I couldn't see how to use them. Is there a way to do this?
EDIT
My program is pretty much complex than the above example and has to use loops. So an answer with loops is appreciable.
If[]
statement in there? Loops are discouraged in Mathematica though... $\endgroup$AppendTo
instead ofAppend
. But anyways, as @Feyre said, useTable
instead ofDo
. And read the documentation more thoroughly. $\endgroup$