Skip to content

Instantly share code, notes, and snippets.

@karlseguin
Created January 17, 2011 11:57
Show Gist options
  • Save karlseguin/782765 to your computer and use it in GitHub Desktop.
Save karlseguin/782765 to your computer and use it in GitHub Desktop.
Handling nhibernate exceptions
using System;
using System.Data.SqlClient;
using NHibernate.Exceptions;
public class ExceptionConverter : ISQLExceptionConverter
{
public Exception Convert(AdoExceptionContextInfo context)
{
var exception = ADOExceptionHelper.ExtractDbException(context.SqlException) as SqlException;
if (exception != null)
{
switch (exception.Number)
{
case 2601:
return new DuplicateKeyException(context.Message, exception.InnerException);
}
}
return SQLStateConverter.HandledNonSpecificException(context.SqlException, context.Message, context.Sql);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment