Variable 'Error' unsafe in 'try'

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


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 ( This is fully understandable.

I've compacted my case to this minimal one:

test() ->
    try ok catch
        _:Error -> Error
    try ok catch
        _:Error -> Error

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?  


More information about the erlang-questions mailing list