I've visited the links and I can tell you that this is exactly what I
was
looking for. I didn't know that was a Jira issue opened for that and
I
started to make something very similar in the project that I work.
if (ex is MySqlException)
{
MySqlException mex = ex as MySqlException;
switch (mex.Number)
{
case (int)MySQLError.DeleteParentRow:
ex = new System.Data.DataException("...");
break;
case (int)MySQLError.DuplicateKey:
ex = new System.Data.DataException("...");
break;
}
}
public enum MySQLError : int
{
[Description("Cannot delete or update a parent row: a foreign key
constraint fails (%s)")]
DeleteParentRow = 1451,
[Description("Can't write; duplicate key in table '%s'")]
DuplicateKey = 1022
}
I'll take a closer look to that Jira issue later.
Thank you,
Cassio Tavares
On 21 out, 15:10, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> Please use the previous post visiting the links and take a look to the
> example I had mentioned there.NH catch exception and use the
> ISQLExceptionConverter where available to re-throw the exception this mean
> that you can manage exceptions as you prefer.
>
> 2008/10/21 CassioT <[EMAIL PROTECTED]>
>
>
>
>
>
> > I'm using version 2.0.1.4000
>
> > Should ISQLExceptionConverter be used by the final developer or inside
> > NHibernate
> > code? In other words, we're gonna catch a database exception and
> > convert it or NHibernate
> > will do this for us?
>
> > Thank you
>
> > Cassio Tavares
>
> > On 21 out, 12:25, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> > > Which version of NH are you using ?
> > > To catch and convert your RDBMS exception the right way is an
> > implementation
> > > of
> > > ISQLExceptionConverter
>
> > > BTWhttp://
> > groups.google.com.ar/group/nhusers/browse_thread/thread/c42e47...
>
> > >http://groups.google.com.ar/group/nhusers/browse_thread/thread/3f2b98...
>
> > >http://groups.google.com.ar/group/nhusers/browse_thread/thread/72c1e8...
>
> > > 2008/10/21 CassioT <[EMAIL PROTECTED]>
>
> > > > Hi,
>
> > > > I was reading an article -
>
> > > >http://today.java.net/pub/a/today/2006/04/06/exception-handling-antip.
> > ..
>
> > > > about exception handling and this paragraph took my attention:
>
> > > > "Wrapping an exception can provide extra information to the user by
> > > > adding your own message (as in the example above), while still
> > > > preserving the stack trace and message of the original exception. It
> > > > also allows you to hide the implementation details of your code, which
> > > > is the most important reason to wrap exceptions. For instance, look at
> > > > the Hibernate API. Even though Hibernate makes extensive use of JDBC
> > > > in its implementation, and most of the operations that it performs can
> > > > throw SQLException, Hibernate does not expose SQLException anywhere in
> > > > its API. Instead, it wraps these exceptions inside of various
> > > > subclasses of HibernateException. Using the approach allows you to
> > > > change the underlying implementation of your module without modifying
> > > > its public API."
>
> > > > I can catch MySql exceptions from nhibernate like this one: "Cannot
> > > > delete or update a parent row" (I know this is only the message but
> > > > the exception type is MySql.Data.MySqlClient.MySqlException)
>
> > > > Is this intentional or it will be modified in the future? What do you
> > > > think about it?
>
> > > > Thanks,
>
> > > > Cassio Tavares
>
> > > --
> > > Fabio Maulo
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---