Ok, but how does an exception fit in? You need to know if there was an error to 
log it or do additional stuff (like MsgBox.Show etc.).

Jaroslaw Kowalski wrote:
Cool, a question on that:
What happens if a exception occurs?
I meand close() gets called at the end of the using block, but does it get also called when an exception occurs (sort of finally)?
If yes, I'm changing my programming style :)
Another question, how would it look like if you had to catch an exception (i.e. to rollback a transaction)?


The following code:

====
using (A a = new A())
{
   code
};
====

Is equivalent to:

=======
A a = null;

try
{
   a = new A();
   /// code
}
finally
{
   if (a != null) ((IDisposable)a).Dispose();
}
=======

It's the C# compiler that translates every using() to something like the above code. The IDisposable.Dispose method on data providers automatically rolls back any open and uncommitted transactions so you don't need to do explicit rollbacks.

BTW. I've seen many (MS and other) examples where they don't call Dispose the IDbCommand object, even though it implements IDisposable, I'm not sure whether it leads to potential resource leaks or not.


--
Emil R. Emilov
-----------------------------------------------------------------------
mailto:[EMAIL PROTECTED]
http://www.emilov.de
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to