在大型Mathematica项目中设置诊断错误消息 [英] Setting up diagnostic error messages in large Mathematica projects

查看:472
本文介绍了在大型Mathematica项目中设置诊断错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我创建一个大型的Mathematica项目时,我都会遇到这个问题:防止Mathematica发生运行时错误, Mathematica的错误信息是不透明的,古老的和军团的。

然后,这个想法是禁用所有Mathematica自己的错误信息,并且实现每个类型检查和错误信息功能和模块。然而,我还没有找到一个简单而有效的方法来完成这个任务,并且最终会产生一些函数,例如产生深度错误20函数调用的函数,然后将所有错误消息级联到主例程。 p>

你将如何为此设置一个简单的机制,只会在遇到错误的函数和函数调用链的简单列表中生成一个错误消息?



编辑:由于它已经出现在几个答案中;我专门寻找轻量级的产品(否则我可以坚持使用Mathematica的错误消息),而且在计算开销方面显然也是轻量级的。因此,虽然 Stack Trace 在开销方面确实很轻,但它们在复杂项目中的输出不易快速解析,工作需要简化它。 b
$ b

重新阅读您的问题......


然后,想法是禁用所有Mathematica自己的错误消息以及您在每个功能和模块中的实现类型检查和错误消息。


$ b

发现这个:

  $ MessagePrePrint =(#; Print [Stack [_] [[;; -5]]]; Abort [])& 

v [x_,y_]:= w [x,y];
w [x_,y_]:= x / y;

StackComplete @ v [1,0];

在评估In [267]时:= {StackComplete [v [1,0]],
StackComplete [v [1,0]],v [1,0], w [1,0],1/0,1/0,消息[Power :: infy,1/0]}

Out [267] = $ Aborted

结论...在第一条消息中放弃并留下合理的堆栈跟踪。 合理的意思是应该改进。



但它是完全非侵入性的!


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, archaic, and legion.

The idea then is to disable all of Mathematica's own error messages and implement type checking and error messages of your own in every Function and Module. However I have not found a simple and efficient way of doing this and end up with, e.g., some function generating an error 20 function calls deep and then get a whole cascade of error messages all the way back up to the main routine.

How would you set up a simple mechanism for this that only generates one error message at the function that experiences the error and a simple list of the chain of function calls?

EDIT: Since it has come up in a couple of answers; I am specifically looking for something lightweight regarding the output it produces (otherwise I could just stick with Mathematica's error messages) and obviously also lightweight in computational overhead. So while Stack and Trace are definitely light on the overhead, their output in complex projects is not quick to parse and some work needs to be done simplifying it.

解决方案

YAsI - Yet Another (silly?) Idea ...

Re-reading your question ...

The idea then is to disable all of Mathematica's own error messages and implement type checking and error messages of your own in every Function and Module.

Found this:

$MessagePrePrint = ( #; Print[Stack[_][[;; -5]]]; Abort[]) &  

v[x_, y_] := w[x, y];
w[x_, y_] := x/y;

StackComplete@v[1, 0];

During evaluation of In[267]:= {StackComplete[v[1,0]];,
          StackComplete[v[1,0]], v[1,0], w[1,0], 1/0, 1/0, Message[Power::infy,1/0]}

Out[267]= $Aborted

conclusion ... Aborts at first message and leaves a "reasonable" stack trace. "Reasonable" means "Should be improved".

But it is completely non-intrusive!

这篇关于在大型Mathematica项目中设置诊断错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆