History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-815
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Cedric Vivier
Reporter: Rodrigo B. de Oliveira
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Boo

except clause variable names are not being checked by the compiler

Created: 08/Apr/07 10:24 AM   Updated: 20/May/08 09:09 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 0.8.3

Time Tracking:
Not Specified

Issue Links:
Related
 


 Description  « Hide
The compiler allows the following code to compile:

try:
raise System.Exception()
except System.ArgumentException:
pass



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Cedric Vivier - 12/Apr/07 03:32 PM
Couldn't reproduce against SVN build :

cedric@laptop:~/dev/workspace/boo-svn/sandbox$ cat exception.boo
try:
raise System.Exception()
except System.ArgumentException:
pass
cedric@laptop:~/dev/workspace/boo-svn/sandbox$ booc exception.boo
Boo Compiler version 0.7.6.2437 (CLR v2.0.50727.42)
exception.boo(3,14): BCE0043: Unexpected token: ..
1 error(s).

However it compiles fine if we import System and then use "except ArgumentException" as shown above.

Should we ensure the "name" is not a type ? or maybe we could allow the "name" to be a type reference here (as long as it is subclassing Exception? [1]) and just handles this transparently as in c# ?

[1] : as far as I know the CLR does not actually have this restriction but well...


Avishay Lavie - 12/Apr/07 04:01 PM
We should definitely ensure "name" does not match the name of a valid type, or rather, if it is, to handle it as such. So these should still be valid:
except ex as ArgumentException:
  ...
except ex:    // (assume "ex as System.Exception")
  ...

And this should probably be valid as well:

except ArgumentException:  // (assume "__unnamed as ArgumentException")
  ...

Cedric Vivier - 12/Apr/07 04:12 PM
Yup we envision the same on this

Let's wait the final word from Rodrigo on this though.


Rodrigo B. de Oliveira - 12/Apr/07 05:54 PM
About the:

And this should probably be valid as well:

except ArgumentException:  // (assume "__unnamed as ArgumentException")
  ...

It should be valid, yes, but the semantics aren't changed. ArgumentException would be a variable name, in other words:

except ArgumentException:

is the same as:

except ArgumentException as System.Exception:

If you want to emit a warning for that I'm cool.


Avishay Lavie - 12/Apr/07 06:23 PM
I think it's important for Boo to support unnamed exceptions in except blocks. Think of the usual:
try:
  i = int.Parse(s)
except FormatException:
  print "That ain't no integer!"

What I'm saying is that sometimes the type of exception is more important than the variable used to capture it. The existing semantics require users to use a dummy variable, which is IMHO contrary to the Boo spirit, being "structure for the sake of structure".


Marcus Griep - 27/Sep/07 07:57 PM
There are some resolution issues in here, though, because I could define a type 'ex' that derives from System.Exception and then try to do this:
try:
  value = 12/0
except ex:
  print "Caught"

In this case, should a variable ex be created, or should it use the type? Or, should we throw an error. I have a patch that I believe has a better, just as wrist-friendly, but clear syntax:

try:
  value = 12/0
except as DivideByZeroException:
  print "Zero can't support a fraction!"

I have created a sister issue regarding exceptions in general. The patch is attached to that issue. If someone decides to use

except ArgumentException:
  pass

then I believe that we could emit a warning that the name is the same as a valid type and suggest the alternate syntax.