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[,
Internal`InheritedBlock[{MessagePacket},
Unprotect[MessagePacket];
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]}, " "],
Black],
obj}], form]]
];
#
], HoldAll];
f[var : _] :=
Block[{arg},
arg = var;
1/arg
];
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.
Thanks!
ParallelMap[withTaggedMsg[arg][f@#] &, Range[-2, 1, 1]]. The inner term can also be writtenwithTaggedMsg[arg]@*f. Do these work for you? – Mr.Wizard Jul 09 '15 at 16:10ProtectedPacketHandler::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>>],MessageName],: ,"Infinite expression !(1/0) encountered."}]}],StandardForm]] received and discarded from KernelObject[2,local].´ – Sos Jul 10 '15 at 12:28Maybe you'd like to post this as an answer?
– Sos Jul 10 '15 at 12:29