This is for sure a bug. You strictly followed The Wolfram System Compiler tutorial, entry Runtime Error Handling in the tool.
On the web there is a description without Throw
.
The thing is, after having thrown one error followed by an errorless evaluation, you can later on throw as much as you want.
In[1]:= Remove[func8]
func8 = Compile[{{v, _Real}}, Sqrt[v - 8], "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]}]
Out[2]= CompiledFunction[{10, 10., 4444}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{-8, {2, 0,
0}}}, {0, 1, 3, 0, 0}, {{10, 0, 1}, {13, 0, 1, 2}, {40, 57, 3, 0,
2, 3, 0, 1}, {1}}, Function[{v}, Sqrt[v - 8]], Throw[$Failed]& ]
In[3]:= Catch[func8[#]] & /@ {1, 15, 16, 17, 18}
During evaluation of In[3]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
Out[3]= {$Failed, 2.64575, 2.82843, 3., 3.16228}
In[4]:= Catch[func8[#]] & /@ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 15, 16, 17, 18}
During evaluation of In[4]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[4]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[4]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[4]:= General::stop: Further output of CompiledFunction::cfn will be suppressed during this calculation. >>
Out[4]= {$Failed, $Failed, $Failed, $Failed, $Failed, $Failed, \
$Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, \
2.64575, 2.82843, 3., 3.16228}
If you throw 3 errors in the beginning, it will never work again, even with offset = 3:
In[8]:= Remove[func3]
func3 = Compile[{{v, _Real}}, Sqrt[v - 3], "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]}]
Out[9]= CompiledFunction[{10, 10., 4444}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{-3, {2, 0,
0}}}, {0, 1, 3, 0, 0}, {{10, 0, 1}, {13, 0, 1, 2}, {40, 57, 3, 0,
2, 3, 0, 1}, {1}},
Function[{v}, Sqrt[v - 3]], Throw[$Failed]& ]
In[10]:= Catch[func3[#]] & /@ {1, 1, 1, 5, 6, 7, 8}
During evaluation of In[10]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[10]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[10]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[10]:= General::stop: Further output of CompiledFunction::cfn will be suppressed during this calculation. >>
Out[10]= {$Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed}
Do this again in the same session
In[14]:= Remove[func31]
func31 = Compile[{{v, _Real}}, Sqrt[v - 3], "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]}]
Out[15]= CompiledFunction[{10, 10., 4444}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{-3, {2, 0,
0}}}, {0, 1, 3, 0, 0}, {{10, 0, 1}, {13, 0, 1, 2}, {40, 57, 3, 0,
2, 3, 0, 1}, {1}},
Function[{v}, Sqrt[v - 3]], Throw[$Failed]& ]
In[16]:= Catch[func31[#]] & /@ {1, 5, 6, 7, 8}
During evaluation of In[16]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
Out[16]= {$Failed, 1.41421, 1.73205, 2., 2.23607}
In[17]:= Catch[func31[#]] & /@ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6,7, 8}
During evaluation of In[17]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[17]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[17]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[17]:= General::stop: Further output of CompiledFunction::cfn will be suppressed during this calculation. >>
Out[17]= {$Failed, $Failed, $Failed, $Failed, $Failed, $Failed, \
$Failed, $Failed, $Failed, $Failed, $Failed, 1.41421, 1.73205, 2., \2.23607}
that works. Condition seems to be: Generate one or two errors then an errorless evaluation and now you can do whatever you want:
Remove[func17]
func17 = Compile[{{v, _Real}}, Sqrt[v - 17], "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[$Failed]}]
In[31]:= func17 /@ {1, 20, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 21, 22,23, 24}
During evaluation of In[31]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[31]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[31]:= CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. >>
During evaluation of In[31]:= General::stop: Further output of CompiledFunction::cfn will be suppressed during this calculation. >>
Out[31]= {$Failed, 1.73205, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, $Failed, \
$Failed, 2., 2.23607, 2.44949, 2.64575}
This is Mathematica 10.0.2.0 under Windows 7 64 Bit Home Premium. Consider to file a bug to Wolfram, please.