Exception handling - Pluggable DAL

Exception handling - Pluggable DAL

Old forum URL: forums.lhotka.net/forums/t/11672.aspx

Arjun posted on Friday, November 02, 2012


I have a project with pluggable DAL. I want to implement exception handling in the project.

I did not write any custom exception class, instead, i tried just "Throw ex" where ever the exception was caught, thinking that it will reach the interface control layer.

The NullReferenceException raised in Data Access Layer was returned to DataPortal_Fetch() in Business Layer. When i throw the caught exception in this method, it was neither thrown to DataPortal.Fetch() nor to the interface control layer.

Please check my code below(psuedo code)


'Interface control layer


public sub CreateItem()



 Catch ex As Exception        ' Exception thrown in Dataportal_Fetch() was not caught here


 End Try

End Sub


Business Layer code


Public shared Sub GetItem()


                  Return DataPortal.Fetch()

        Catch ex As Exception     ' Exception thrown in DataPortal_Fetch() was not caught here

                       Throw ex

        End Try

End Sub


Private Overloads Sub DataPortal_Fetch()


       'Call a method in  Data Access layer where nullreference exception was thrown

Catch ex as Exception

              Throw ex         ' Where do this ex will be thrown to ?

End Try

End Sub



Please let me know how can I implement Exception Handling in Pluggable DAL project. (The "Csla - Data Access" book has only one page information on Exception handling in Pluggable DAL. )

An Example would help a lot. :)



JonnyBee replied on Friday, November 02, 2012

Which type of exception handling are you looking for?

For logging on the server side?

For logging and change the actual exception returned to the client?

Which version of CSLA?

Do you use DataPortal_XYC methods (and repository pattern) or ObjectFactory classes?

Arjun replied on Sunday, November 04, 2012

Hi Jonny,

I am looking for something like, when an exception was thrown in data layer, regardless of the database (SQL or Oracle or Mock database) same exception message should be shown to the user.

For now, not looking at logging the exception in server.

The CSLA framework I i use is 4.0.

Yes I do use DataPortal_XYC methods, but in Data Access layer (not in BO layer) as my project architecture has a seperate layer for Data Access methods.




JonnyBee replied on Sunday, November 04, 2012

A. You can display a generic message ("Something went wrong") but inadvertently SqlServer and Oracle database driver will give different errors, reason codes and messages. So to give the same message would not be my recommended solution.

The simplest solution is to build an ExceptionHandler on the client to inspect the error and message. On the "server" side - and assuming you are using CSLA for N-tier deployment - I would simply log the Exception thrown to have the actual Exception logged serverside.

Can you post a complete sample app as attachment to a post here? 
I suspect something is wrong with your code.

Copyright (c) Marimer LLC