# Plotting an InterpolatingFunction outside its domain doesn't raise error messages

Let's make an InterpolatingFunction:

if = Interpolation[Transpose[{#, Sin@#} &@Range[0, 4, 0.1]]];


As expected, evaluating it outside of its domain switches from interpolation to extrapolation, giving a pretty wacky result. However, Mathematica helpfully warns you about this

if
(* InterpolatingFunction::dmval: Input value {10} lies outside the range of data in the interpolating function. Extrapolation will be used.

36.3612 *)


However, when I go and Plot it, no such warning is offered:

Plot[if[t], {t, 0, 10}] This is in Mathematica 12.0+. I have a strong recollection that I used to get warnings when I tried to plot InterpolatingFunctions outside their domain, and if at all possible I would really like to have that behavior back.

• You could flag it using ColorFunction, e.g., Plot[if[t], {t, 0, 10}, ColorFunction -> Function[{t, f}, If[t > if[[1, 1, -1]], Red, ColorData]], ColorFunctionScaling -> False] Feb 24, 2021 at 18:13
• For better or for worse, Plot[] does suppress error messages. Consider the following: test[t_] := If[TrueQ[Between[t, if["Domain"]]], if[t], Message[InterpolatingFunction::dmval, t]; Undefined]; Plot[test[t], {t, 0, 10}] Feb 24, 2021 at 19:23
• You could instead use: if = Interpolation[Transpose[{#, Sin@#} &@Range[0, 4, 0.1]], "ExtrapolationHandler" -> {Indeterminate &, "WarningMessage" -> False}] so that extrapolation is not used. Feb 24, 2021 at 19:31

It is not possible to override the Quiet run of the command Plot. However, you can intercept the messages and store them in a list to be browsed afterwards.

For example,

errorlst = {};
Plot[if[t], {t, 0, 10},
EvaluationMonitor :>
If[Length[$$MessageList] > 0, AppendTo[errorlst, {$$MessageList[[-1]], t}]]
]


To get the error messages later on, do:

Map[Message[# // Sequence] &, errorlst];