I haven't seen anybody comment on this yet, and I haven't been able to come up with some use for it, but it does seem like there ought to be something clever that you could do with it:

Consider these two short functions:

VB Code:
  1. private function func1(ByRef n as integer) as integer
  2.  n=5
  3.  return n
  4.  
  5.  n=6
  6.  
  7. end function
  8.  
  9. private function func2(ByRef n as integer) as integer
  10.  try
  11.   n=5
  12.   return n
  13.  catch ex as exception
  14.   'Do nothing here.
  15.  Finally
  16.    n=6
  17.  end try
  18. end function

Now consider using the two in this fashion:

VB Code:
  1. public sub Main()
  2.   dim v as integer
  3.   dim n as integer
  4.  
  5.   n=0
  6.   v=func1(n)
  7.  
  8.    'What does n equal? What does v equal?
  9.  
  10.    n=0
  11.    v=func2(n)
  12.  
  13. end function

It may appear that after calling func1 or func2, the variables v and n would be set to the same thing. Afterall, the only difference between the two functions is that func2 has error handling, which will never be called because no errors will arise in that code.

However, the results will not be the same. After calling func1, both n and v will be set to 5. After calling func2, v is 5, but n is 6!

In func1, the function returns at the return statement, and the n=6 line is never executed. In func2, the return simply sets the return to 5, but then the finally block executes, and n is set to 6. Since n is passed by reference, it is changed.

I can't think of an obvious use for this, but it seems there is a window there to use a Finally block to do some odd things.

Any ideas?