Setting up diagnostic error messages in large Mathematica projects

前端 未结 5 1870
春和景丽
春和景丽 2020-12-10 02:12

Whenever I create a large Mathematica project I run into this problem: Preventing avalanche of runtime errors in Mathematica, i.e., Mathematica\'s error message are opaque,

5条回答
  •  囚心锁ツ
    2020-12-10 02:36

    To get the ball rolling here is one idea that I've been toying with; the creation of a pseudo stack.

    First make a global variable theStack={} and then in every Function or Module start with AppendTo[theStack,"thisFuncName"] and end with theStack=Most@theStack. Assuming moderate (~a few tens) depth of function calls, this should not add any significant overhead.

    Then implement your own typing/error checking and use Print@theStack;Abort[]; on errors.

    Refinements of this method could include:

    1. Figuring out a way to dynamically get "thisFuncionName" so that the AppendTo[] can be made into an identical function call for all Functions and Module.
    2. Using Message[] Instead of Print[].
    3. Pushing other important variables / stateful information on theStack.

提交回复
热议问题