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

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

问题描述

每当我创建一个大型 Mathematica 项目时,我都会遇到这个问题:防止 Mathematica 中出现大量运行时错误,即,Mathematica 的错误消息是不透明的、陈旧的和大量的.

然后的想法是禁用所有 Mathematica 自己的错误消息,并在每个函数和模块中实现您自己的类型检查和错误消息.但是,我还没有找到一种简单而有效的方法来执行此操作,并且最终会得到,例如,某些函数会在深度调用 20 次函数时生成错误,然后将整个级联的错误消息一直返回到主例程.

您将如何为此设置一个简单的机制,仅在遇到错误的函数处生成一条错误消息以及函数调用链的简单列表?

因为它已经出现在几个答案中;我特别在寻找关于它产生的输出的轻量级的东西(否则我只能坚持使用 Mathematica 的错误消息)并且显然在计算开销方面也是轻量级的.因此,虽然 StackTrace 的开销确实很轻,但它们在复杂项目中的输出不能快速解析,需要做一些工作来简化它.

解决方案

YAsI - 另一个(傻?)想法...

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

然后的想法是禁用所有 Mathematica 自己的错误消息,并在每个函数和模块中实现您自己的类型检查和错误消息.

找到这个:

$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, Message[Power::infy,1/0]}退出[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天全站免登陆