Variable 'Error' unsafe in 'try'

Adam Lindberg adam@REDACTED
Fri Oct 2 09:30:46 CEST 2009


Hi!

I'm working with some try-catch exceptions and have stumbled upon something which I think is a bit wierd. There was an explanation a year ago on the mailing list which explained why variables bound inside the try-catch expression were not safe to use when an exception got caught (http://erlang.org/pipermail/erlang-bugs/2008-November/001083.html). This is fully understandable.

I've compacted my case to this minimal one:

test() ->
    try ok catch
        _:Error -> Error
    end,
    try ok catch
        _:Error -> Error
    end.

I get an error saying that the variable 'Error' is unsafe in the first line of the function (the first try-catch statement). With just one try-catch statement it works fine.

Why is this? I was under the impression that stuff inside try-catch statements were block local, but that isn't the case? I can't access Error outside the try-catch statement so it shouldn't be a problem, should it?  

Cheers,
Adam


More information about the erlang-questions mailing list