Blog Stats
  • Posts - 157
  • Articles - 0
  • Comments - 90
  • Trackbacks - 19

 

Spot the bug

Today I was reviewing some code. Now who can spot the exception that can be thrown in the finally block? I will give you a couple of hints:

  1. To prevent exceptions from being thrown the Open-Closed principle needs to be violated
  2. The second hint is directly related to the solution: RTTI

using(IDbTransaction transaction = connection.BeginTransaction(IsolationLevel.Serializable)) { IDbDataAdapter dataAdapter = null; try { dataAdapter = CreateDataAdapter(); dataAdapter.UpdateCommand = updateCommand; dataAdapter.UpdateCommand.Connection = connection; dataAdapter.UpdateCommand.Transaction = transaction; dataAdapter.TableMappings.Add("Table", "S114_PTCAR"); dataAdapter.Update(Ptcars); transaction.Commit(); } finally { ((IDisposable) dataAdapter).Dispose(); } }

I will post the solution tomorrow.


Windows Live Writer Syntax Highlighter plug-in by Christoph De Baene


Cross-posted from The .NET Aficionado
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Spot the bug

Gravatar You don't know that dataAdapter implements IDisposable, so it's possible to get an InvalidCastException. 10/30/2006 8:46 PM | Jason Bock

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Gabriel Lozano-Morán