Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running a calculation to generate a dataset. I use several iterations to sweep over a parameter space. A few times an error message is generated (which is not the problem per se). Is it possible to output the value of the iterative variables (or other local variables) for each generation of an error message, without interrupting the evaluation, in order for me to check what is going wrong?

I tried (without success)something like this:

messageHandler = If[Last[#], Print[i]] &;
Internal`AddHandler["Message", messageHandler];

for a code that could be something like:


My code is of course much more complex so that I do not want to use Trace, that outputs a huge amount of data that I cannot read. I tried the debugger in the WorkBench but it seemed like I could not access the local variables after a message interruption.

Anyone has a simple Idea?

share|improve this question
up vote 1 down vote accepted

You can do that with the function Check:

 Check[1/i, Print["i = ", i]], {i, -5, 5}

Mathematica graphics

Here, 1/i takes the place of your complicated code.

share|improve this answer
Thanks for your quick answer! – Felix.k May 18 '14 at 20:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.