# How to output local variables when error message is generated without interrupting evaluation?

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]] &;
InternalAddHandler["Message", messageHandler];


for a code that could be something like:

For[i=1,i<=imax,i++,
(*code*)
]


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?

-

You can do that with the function Check:
Do[

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