I have a Mathematica file called myUsefulFunctions.m containing, for example, a function called mySuperUsefulFunction. Suppose I call mySuperUsefulFunction in a notebook and get the following error:
Part::pspec: Part specification #1 is neither an integer nor a list of integers. >>
Is there a way to find the line in myUsefulFunctions.m where this error occurred?
I don’t know of a way to find the line in the file, which I assume was read without error.
You can however use
Traceand related functions to see where in the evaluation chain the error occurs.Example:
With
Trace:You can see that just before
Message[Part::pspec, #1]is called, which results in a long mess of formatting, we had:{myFunc1[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, #1], {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}[[#1]]This shows that
myFunc1[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, #1]is called, and this causes evaluation of{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}[[#1]]which is clearly in error.Please see this question and its answers for a more convenient use of
Trace:https://stackoverflow.com/q/5459735/618728