Catching ORMException

Posts   
 
    
Posts: 77
Joined: 05-May-2005
# Posted on: 03-Nov-2009 18:41:29   

I am not new to LLBLGen, but I am new to v2.6. I am using LLBLGen Final (Oct. 9th 2009) with the .NET 2.0 SQL Server self servicing templates.

I find that I am unable to catch the ORMException locally in a simple console application. This was never a problem in my .NET 1.1 project, so I'm stumped. Please note that I am deliberately trying to create an exception to test my exception handling logic. Here's the code:

        Eu66Entity eu66 = new Eu66Entity();
        <initialize entity fields>
        eu66.FailCd = 0;    // this value must be > 0 as defined by DB constraint
        try
        {
            eu66.Save();
        }
        catch (ORMException ormEx)
        {
           <exception handling code>
        }

The exception does not bubble up to this try/catch as I expected. Instead I get an unhandled exception error in the InsertEntity() method of the entity class. What am I missing?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Nov-2009 20:59:14   

What are the details of the exception that you are getting ?

Matt

Posts: 77
Joined: 05-May-2005
# Posted on: 03-Nov-2009 21:35:27   

**Window Title: **ORMQueryExecutionException was unhandled by user code. **Window Message: **An exception was caught during the execution of an action query: The INSERT statement conflicted with the FOREIGN KEY constraint "RefFAIL_CODE2". The conflict occurred in database "SBS", table "dbo.FAIL_CODE", column 'FAIL_CD'. The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

This occurs at the "return dao.AddNew(base.Fields, base.Transaction);" statement in the InsertEntity method of the Entity class.

I have already tried specifically catching the ORMQueryExecutionException, but that doesn't work either.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Nov-2009 21:53:09   

And when you say "Doesn't work" - what actually happens ? Is this running inside VS ? What happens if you run the compiled version...?

Matt

Posts: 77
Joined: 05-May-2005
# Posted on: 03-Nov-2009 23:03:47   

When I run in VS debug mode I get the unhandled exception message box which generates an automatic breakpoint and the program will not continue exectuing beyond that point.

When I run the executable outside of VS a window displays with the message "<app name> has encountered a problem and needs to close. We are sorry for the inconvenience. Please tell Microsoft blah blah".

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Nov-2009 11:13:09   

Can you catch the exception if you don't specify the type for it? Or just used the "Exception" base class?

If that's the case then most probaly there is a type mismatch somewhere. Please make sure that you are referencing the same version of the ORMSupportClasses dll, through out your solution (application and generated code).

Also make sure you re-build the entire solution, and that the code is generated for .NET 2.0.

Posts: 77
Joined: 05-May-2005
# Posted on: 18-Nov-2009 20:28:18   

Sorry - got sidetracked by other projects.

I cannot catch the exception if I don't specify the type. I cannot catch the exception using the Exception base class.

All projects in the solution are referencing the same version of the support classes DLL.

I have rebuilt the entire solution; however, I am targeting the .NET 3.5 framework.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Nov-2009 05:02:22   

Should work perfectly on Release mode. Please paste your <handle exception code> (the catch part).

David Elizondo | LLBLGen Support Team
Posts: 77
Joined: 05-May-2005
# Posted on: 19-Nov-2009 16:13:16   

I had not gotten around to running in release mode yet. You are correct - it works perfectly in Release mode. Is there a way to way to make it work the same way in Debug mode?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Nov-2009 04:21:51   

I think you are looking for something like Just Step Into My Code (from MSDN)

David Elizondo | LLBLGen Support Team
Posts: 77
Joined: 05-May-2005
# Posted on: 20-Nov-2009 16:29:40   

That's helpful, but I'm confused as to why the generated code behaves this way. This was not the case with LLBLGen for .NET 1.1. I ran in debug mode all the time and if I had an exception handler I did not get automatic break points in the entity class when a DB exception occurred. Why the change?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Nov-2009 21:36:22   

jlkInChantillyVA wrote:

That's helpful, but I'm confused as to why the generated code behaves this way. This was not the case with LLBLGen for .NET 1.1. I ran in debug mode all the time and if I had an exception handler I did not get automatic break points in the entity class when a DB exception occurred. Why the change?

By LLBLGen for .NET 1.1 you mean LLBLGen Pro v2.6 with .NET 1.1 target platform templates or another version of LLBLGen?

David Elizondo | LLBLGen Support Team
rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 22-Nov-2009 22:40:31   

Not sure if this will help you, but it's worth a shot.

Hit CTRL-ALT-E in Visual Studio and make sure CLR Exceptions is checked.

Hope this helps. Good luck,

Ryan