Hi everybody.
I need to register custom exception for NHibernate dialect. I have implemented and registered ISqlExceptionConverter, as shown in NHibernate tests. But when exception in code throws, it is not converted. My conversion code even does not call.
My code is really simple:
try
{
using (ISession sess = OpenSession())
using (ITransaction tx = sess.BeginTransaction())
{
....
sess.Save(obj); // invalid object scheduled for inserting
.....
tx.Commit(); // exception raises here
}
}
catch (UniquenessViolationException ex)
{
// never came here, since exception was not converted and is of type
HibernateException
}
My ISqlExceptionConverter implementation:
public class SqlExceptionConverter : ISQLExceptionConverter
{
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqlEx = ADOExceptionHelper.ExtractDbException
(exInfo.SqlException) as SqlException;
if (sqlEx != null)
{
if (sqlEx.Number == 2627)
return new UniquenessViolationException(exInfo.Message, sqlEx,
exInfo.Sql);
}
return SQLStateConverter.HandledNonSpecificException
(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}
Maybe i missed something?