2
$\begingroup$

I have been using my intuition to solve errors in my Mathematica scripts. But when calculations got more complex and I started getting errors involving code in more participating scripts (a script needs another one which needs another one, etc.), I searched for a way to find a file and line number or something and I found:

How to find line where error occurred in Mathematica notebook?

and

The clearest way to represent Mathematica's evaluation sequence

both of them more appropriate to the notebook (UI) environment. I can probably use a notebook and try to run my script there; but I wonder if there is a better way to work purely command line.

Any ideas?

(I am using Mathematica version 9)

$\endgroup$
10
  • $\begingroup$ If you want to work under CLI, one way to debug is to insert Print["your label"] at the place you're interested in. If you want to find a file where the current function is defined in, you may need Trace-family (e.g. TraceScan). $\endgroup$
    – Silvia
    Aug 4 '14 at 6:10
  • $\begingroup$ btw. I think it will describe the question better if you state in the title that you are doing the debug under command line. $\endgroup$
    – Silvia
    Aug 4 '14 at 6:22
  • $\begingroup$ That's what I've been doing. But when you start having more participating scripts and/or logic gets more elaborated, it becomes harder... Sad that Mathematica does not have "exceptions" but the messaging approach. $\endgroup$
    – carlosayam
    Aug 4 '14 at 6:23
  • $\begingroup$ There are functions like Assert, Check, etc. might help you beyond the Print approach. $\endgroup$
    – Silvia
    Aug 4 '14 at 6:25
  • 1
    $\begingroup$ Possibly related: (3837) $\endgroup$
    – Mr.Wizard
    Aug 4 '14 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.