Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

Following this question and the comments made, together with the information in this question, the following code allows error tracking and debugging very nicely.

SetAttributes[withTaggedMsg, HoldAll];

withTaggedMsg[sym_] := Function[,
    MessagePacket[name__, BoxData[obj_, form_]] /; ! TrueQ[$tagMsg] :=
          Block[{$tagMsg = True},
        Identity@MessagePacket[name, BoxData[RowBox[{
          ToBoxes @ Style[
            Row[{"At iteration", HoldForm[sym], "=", sym, Spacer[5]}, " "],
        obj}], form]]
  ], HoldAll];

f[var : _] :=
    arg = var;

Map[f[#] &, Range[-2, 1, 1]] // withTaggedMsg[arg]

(*At iteration arg=0  Power::infy : Infinity expression 1/0 encountered.
{-(1/2), -1, ComplexInfinity, 1}*)

Now, the big problem is how to use withTaggedMsg together with ParallelMap instead of Map.

ParallelMap[f[#] &, Range[-2, 1, 1]] // withTaggedMsg[arg]

(*At iteration arg=arg Parallel`Protected`PacketHandler::default: Unhandled packet MessagePacket[Power,infy,BoxData[RowBox[{StyleBox[RowBox[{Power,::,infy}],
MessageName],: ,"Infinite expression \!\(1\/0\) encountered."}],StandardForm]] received and discarded from KernelObject[6,local].
{-(1/2), -1, ComplexInfinity, 1}*)

I don't see how I could do it, and would appreciate immensely if I could get some input in this.


share|improve this question
I found this question today while retagging posts. I don't believe I have seen it before. Are you still hoping for an answer? – Mr.Wizard Jul 9 '15 at 1:58
I guess not, no. Sorry if it stayed here for too long. Should I close it? – Sosi Jul 9 '15 at 10:09
Surely it is not your fault that nobody answered. Incidentally in 10.1.0 under Windows this appears to work: ParallelMap[withTaggedMsg[arg][f@#] &, Range[-2, 1, 1]]. The inner term can also be written withTaggedMsg[arg]@*f. Do these work for you? – Mr.Wizard Jul 9 '15 at 16:10
Indeed, it works, but it isn't as pretty as the one above (ofc, this isn't a problem): ´ParallelProtectedPacketHandler::default: Unhandled packet MessagePacket[Power,infy,...iteration",TagBox[<<2>>],"=",0,... {GrayLevel[0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, Frame->True, FrameStyle->GrayLevel[0.], FrameTicks->None, ImageSize->{Automatic, 10.8}, PlotRangePadding->None]),StripOnInput->False],RowBox[{StyleBox[RowBox[<<1>>],Me‌​ssageName],: ,"Infinite expression \!(1\/0) encountered."}]}],StandardForm]] received and discarded from KernelObject[2,local].´ – Sosi Jul 10 '15 at 12:28
(sorry for the messy comment. but you can see that ´iteration,...=,0´, similarly to the code above.) Maybe you'd like to post this as an answer? – Sosi Jul 10 '15 at 12:29

Your Answer


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

Browse other questions tagged or ask your own question.