On Wed, 14 Oct 2015, Sven Schreiber wrote:
Hi,
it wasn't easy hunting this one down in the sense of provoking the error
in a small (probably not minimal) example:
<hansl>
open denmark
function scalar heyhey (list in)
var 20 in # 20 is too much -> error
return 3
end function
if 5 < 10
list lulu = LRM LRY IBO IDE
catch scalar what = heyhey(lulu)
if $error
print "aha"
endif
endif
</hansl>
When I run this under Sep 20th's snapshot I get an error telling me I
have an unmatched "endif" ('ungepaartes "endif"' in German),
which I
think is quite obviously not true.
This is now fixed in git -- but the fix is that you're not allowed to
use "catch" on a call to a user-defined function (and will see an
error message to that effect).
The point is that catch must always be applied directly to the gretl
command (or built-in function) that might generate an error. In your
example, the "var" command inside the function generates an (uncaught)
error. In response to that error gretl aborts execution of the
function and gets ready to abort execution of the script. And that
involves tearing down any "if" conditionality that's currently in
force (otherwise it will mess up subsequent script execution).
However, when control returns to "main" gretl finds that catch is in
place so it soldiers on, and encounters "endif", which is now
"unmatched" since the preceding "if" has been erased. So this sort of
thing is not going to work; you can't do a "delayed" catch, or in
other words the catch must be moved inside the function.
Allin