weird behavior of catch scoping rules
Posted: Sat Jan 17, 2009 2:27 am
Consider the current behavior of Cobra in three similar programs.
I can understand the error in Program1, taking into account that Cobra's loose block scoping rules are based on Python.
With that in mind, I can understand Program 2 as well, although I would expect it to issue a warning that said something like "you can remove as Exception, since ex is already of that type".
But what I don't understand is Program3. From programs 1 and 2 it is clear that ex is still on scope, so then why is it that the compiler chokes when it finds "ex" without a type?
class Program1
def main is shared
try
pass
catch ex as Exception
pass
try
pass
catch ex as FormatException # Compiler error: redeclaration of ex from Exception to FormatException
pass
class Program2
def main is shared
try
pass
catch ex as Exception
pass
try
pass
catch ex as Exception # Works, since type of ex is preserved
pass
class Program3
def main is shared
try
pass
catch ex as Exception
pass
try
pass
catch ex # Compiler error: cannot find type of ex
pass
I can understand the error in Program1, taking into account that Cobra's loose block scoping rules are based on Python.
With that in mind, I can understand Program 2 as well, although I would expect it to issue a warning that said something like "you can remove as Exception, since ex is already of that type".
But what I don't understand is Program3. From programs 1 and 2 it is clear that ex is still on scope, so then why is it that the compiler chokes when it finds "ex" without a type?