Simon Green's Developer Blog
Developing .NET in the cold white north ...

Minor Update to NHibernate Helper Project

Thursday, 21 July 2005 16:28 by Simon

Someone pointed out a mistake with the NHibernate Helper Project which has now been updated:

You should never rethrow an exception you've caught as you lose stack trace information.  Rather than:

try
{
   thing.Save();
   transaction.Commit();
}
catch (Exception ex)
{
   transaction.Rollback();
   throw ex;
}

do:

try
{
   thing.Save();
   transaction.Commit();
}
catch (Exception)
{
   transaction.Rollback();
   throw;   // doesn't lose stacktrace.
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:  
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 20. 2008 19:43