Created
January 17, 2011 11:57
-
-
Save karlseguin/782765 to your computer and use it in GitHub Desktop.
Handling nhibernate exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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