Michael Maddison
michael at ddisolutions.com.au
Fri Jul 23 00:57:00 CDT 2010
BTW, The finally is executed before the error bubbles up to calling method. Cheers Michael M -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Friday, 23 July 2010 3:12 PM To: VBA Subject: [dba-VB] try catch finally OK, so I am trying to learn exception handling. One of the things I am reading is to make heavy use of finally to do cleanup. Fine, except I am ending up with scope issues. for example: Try { set a new connection open a new reader Do something with the reader close the reader close the connection } catch(sqlexception) { handle the sql errors throw; } catch (exception) { handle the nonsql errors throw; } finally { } Logically the close of the reader and connection should go in the finally, with the catch catching any issues actually opening the connection or reader. That doesn't work however because the connection and reader are not in scope in the finally block. It appears that the dimensioning of the connection and reader have to go before the try in order for the finally to see the scope? I assume that the finally block executes after the throw? What happens to the execution thread on a throw? Does the thread execute code up in any sink up above? Does execution return back into this block of code after the code up in the the parent sink finishes executing? I am so confused. ;) -- John W. Colby www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com